【发布时间】:2012-01-06 16:24:41
【问题描述】:
如果 DataGrid 中的新/旧项目但偶然发现错误,我正在尝试将单元格设为粗体或正常。
看起来我的问题在这里描述:Why can I not bind the Visiblity of a DataGridTemplateColumn in Silverlight 4?
我收到以下错误:
“System.Windows.Data.Binding”类型的对象无法转换为 输入“System.Windows.FontWeight”。
我的 XAML 看起来像这样:
<sdk:DataGridTextColumn Header="Subject" Binding="{Binding Subject}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" FontWeight="{Binding IsNew, Converter={StaticResource BoolToFontWeightConverter}}" />
我的问题是有什么解决方法可以让它工作吗?我什至没有使用模板列,它是纯文本列..
public class BoolToFontWeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((bool)value) ? FontWeights.Bold : FontWeights.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (FontWeight)value == FontWeights.Bold;
}
}
【问题讨论】:
-
你的转换器的返回类型是否等于FontWeight类型?
-
转换器代码永远不会被命中 - 我添加了代码
-
很遗憾,
FontWeight不是依赖属性 -
有什么变通办法让它工作吗?也许创建我自己的 Grid 列?
标签: c# silverlight xaml