【发布时间】:2013-11-15 15:10:04
【问题描述】:
也许我误解了如何使用 IValueConverter 或数据绑定(这很可能),但我目前正在尝试根据字符串的值设置 DataGridTextColumn 的 IsReadOnly 属性。这是 XAML:
<DataGridTextColumn Binding="{Binding Path=GroupDescription}" Header="Name"
IsReadOnly="{Binding Current,
Converter={StaticResource currentConverter}}"/>
这是我的转换器:
public class CurrentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string s = value as string;
if (s == "Current")
{
return false;
}
else
{
return true;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
目前,该列始终是可编辑的,转换器似乎什么都不做。有人对为什么会发生这种情况有一些想法吗?
【问题讨论】:
-
问题/问题是什么?
-
更新了问题的结尾,希望不会太含糊...
-
IsReadOnly 不可绑定。在stackoverflow.com/questions/18443063/… 上查看我的回答
-
@Shoe -
IsReadOnly可以像任何其他 DP 一样绑定。 -
@mastur -
Current的财产在哪里?在您的 ViewModel 类或底层 ItemsSource 对象中?
标签: c# wpf data-binding