2017-08-01 71 views
0

我不能绑定设置columncell的前景,如果我使用的XAML语法:如何设置前景色与质感设计结合:MaterialDataGridTextColumn

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

在Windows负载的输出端子我看到:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Foreground; DataItem=null; target element is 'MaterialDataGridTextColumn' (HashCode=29149718); target property is 'Foreground' (type 'Brush')

如果我把例如直接颜色:

<materialDesign:MaterialDataGridTextColumn Foreground="Red"/> 

DataGrid的切尔l正确渲染前景,有没有人有一些建议?

问候

佛朗哥

回答

0

我找到了解决办法!

我有ElementStyle物业工作:

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

我希望这是有用的给别人。

问候

佛朗哥