I have a scenario where I need to specify Functions like
void SomeFunction(int value)
For this I'm using two DataGrid
s.
DataGrid
holds the FunctionsDataGrid
holds the Parameters for the selected FunctionI only want the Parameter DataGrid
to be enabled when a valid Function is selected in the Function DataGrid
. If the NewItemPlaceHolder
(the Last Row when CanUserAddRows="True"
for a DataGrid
) is selected or if the selection is empty I want it to be disabled. I experimentet with a DataTrigger but I couldn't 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 produced by the Binding is of a specific Type
? Otherwise, does anyone have any other solutions to this? As of now, I'm handling this with the SelectedCellsChanged
event but I would prefer not using code behind
Thanks
If anyone else comes across the same problem, here's what I did to solve it. I created a TypeOfConverter
that returns the Type
of the value produced 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();
}
}
Have you considered a DataTemplate for the right DataGrid (parameters)?
Then you could bind the DataContext of your right DataGrid to the SelectedItem of the left DataGrid.
And in your DataTemplate, you can make your right side look like an enabled DataGrid parameter entry form when the DataTemplate's DataType={x:Type local:FunctionObject}. When a 'FunctionObject' is not selected you can have a DataTemplate for that too which shows a disabled DataGrid parameter entry form, or you could choose to display nothing as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With