我有一个需要指定函数的场景
void SomeFunction(int value)
为此,我使用了两个 DataGrid
。
- 左边的
DataGrid
包含函数 - 右侧的
DataGrid
包含所选函数的参数
我只希望在函数 DataGrid
中选择有效函数时启用参数 DataGrid
。如果 NewItemPlaceHolder
(当 CanUserAddRows="True"
用于 DataGrid
时的最后一行) 被选中,或者如果选择为空我希望它被禁用。我尝试使用 DataTrigger,但无法让它工作
<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>
是否可以检查 Binding 产生的值是否属于特定的 Type
?否则,有人对此有任何其他解决方案吗?截至目前,我正在使用 SelectedCellsChanged
事件处理此问题,但我宁愿不使用代码隐藏
谢谢
最佳答案
如果其他人遇到同样的问题,这就是我所做的解决方法。我创建了一个 TypeOfConverter
,它返回 Binding 产生的值的 Type
。
<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();
}
}
关于c# - 特定类型的数据触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5091695/