DataTrigger for a specific type

I have a scenario where I need to specify functions such as

void SomeFunction(int value) 

For this, I use two DataGrid s.

  • The left DataGrid contains functions
  • The right DataGrid contains the parameters for the selected function

I want the DataGrid parameter to turn on when a valid function is selected in the DataGrid function. If NewItemPlaceHolder selected (the last row when CanUserAddRows="True" for the DataGrid ), or if the selection is empty, I want it to be disabled. I am experimenting with a DataTrigger, but I could not get it to work

 <Style TargetType="DataGrid"> <Setter Property="IsEnabled" Value="False"/> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=functionDataGrid, Path=SelectedItem}" Value="{x:Type systemData:DataRowView}"> <Setter Property="IsEnabled" Value="True"/> </DataTrigger> </Style.Triggers> </Style> 

Is it possible to check if the value created by the binding has a specific Type value? Otherwise, does anyone have any other solutions? I am currently handling this with the SelectedCellsChanged event, but I would prefer not to use the code for

thanks

+7
source share
2 answers

If someone else is facing the same problem, here is what I did to solve it. I created a TypeOfConverter that returns the Type value created by the binding.

 <DataTrigger Binding="{Binding ElementName=functionsDataGrid, Path=SelectedItem, Converter={StaticResource TypeOfConverter}}" Value="{x:Type data:DataRowView}"> <Setter Property="IsEnabled" Value="True"/> </DataTrigger> 

TypeOfConverter

 public class TypeOfConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (value == null) ? null : value.GetType(); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } 
+7
source

Have you considered a DataTemplate for the correct DataGrid (parameters)?

You can then bind the DataContext of your proper DataGrid to the SelectedItem of the left DataGrid.

And in your DataTemplate, you can make your right side look like the included DataGrid data entry form when DataTemplate DataType = {x: Type local: FunctionObject}. When "FunctionObject" is not selected, you can have a DataTemplate for this that shows the disabled DataGrid parameter input form, or you can also display nothing.

+3
source

All Articles