如何设置前景与绑定材料设计:材料数据网格文本列



如果我在 xaml 中使用该语法,我无法设置带绑定的列单元格的前景:

<materialDesign:MaterialDataGridTextColumn Foreground="{Binding Foreground}"/>

在输出终端的窗口加载中,我看到:

System.Windows.Data 错误:2:找不到目标元素的管理框架元素或框架内容元素。绑定表达式:路径=前景;数据项=空;目标元素是 'MaterialDataGridTextColumn' (HashCode=29149718(;目标属性为"前景"(类型"画笔"(

如果我以直接颜色为例:

<materialDesign:MaterialDataGridTextColumn Foreground="Red"/>

数据网格单元正确呈现前景,有人有什么建议吗?

此致敬意

佛朗哥

我找到了解决方案!

我必须使用元素样式属性:

<DataGridTextColumn Binding="{Binding Name}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{Binding Foreground}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

我希望这对其他人有用。

问候

佛朗哥

最新更新