J'ai un combobox et un bouton sur mon formulaire. Le combobox a des catégories en eux. Je veux autoriser/interdire en attente s'il s'agit d'une 'catégorie système' basée sur un booléen.WPF/C# IDataErrorInfo ne pas tirer
Voici mon XAML:
<Window.Resources>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
Ceci est le panneau de la pile avec les deux contrôles en eux:
<StackPanel Grid.Column="1" Grid.Row="1">
<Label Content="Delete Category" Height="28"/>
<ComboBox x:Name="comboBox_DeleteCategory"
Grid.Row="1"
Height="29"
ItemsSource="{Binding Path=CategorySelected.Items, ValidatesOnDataErrors=true, NotifyOnValidationError=true}"
SelectedItem="{Binding Path=CategorySelected.SelectedItem ,ValidatesOnDataErrors=True, NotifyOnValidationError=true}"
DisplayMemberPath="Name"/>
<Button Content="Delete" Height="25" Margin="0,5,0,0" HorizontalAlignment="Right" Width="103.307" Command="{Binding DeleteCommand}"/>
</StackPanel>
Je suis en train d'obtenir le combobox pour montrer une info-bulle s'il est déterminé que c'est une catégorie de système. La commande DeleteCommand fonctionne correctement, donc je n'ai pas de problème avec le bouton étant désactivé lorsque je reçois un hit sur la catégorie du système.
Ceci est mon code pour afficher l'info-bulle:
#region IDataErrorInfo Members
public string Error { get; set; }
public string this[string columnName]
{
get
{
Error = "";
switch (columnName)
{
case "comboBox_DeleteCategory":
if (CategorySelected.SelectedItem != null && CategorySelected.SelectedItem.IsInternal)
{
Error = CategorySelected.SelectedItem.Name + " is an system category and cannot be deleted.";
break;
}
break;
}
return Error;
}
}
#endregion
Toutes les suggestions?
Merci,
Eroc