wpf xamdatagrid 行背景颜色数据触发器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23980383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xamdatagrid row background color datatrigger
提问by Gilad
I'm trying to change the color of my row in Xamdatagrid I have a boolean which I want to bind into it.
我正在尝试更改 Xamdatagrid 中我的行的颜色我有一个我想绑定到它的布尔值。
I'm trying to use this http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10103
我正在尝试使用这个 http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10103
here is my code: I'm having a problem with the style:
这是我的代码:我的样式有问题:
igDP:XamDataGrid DataSource="{Binding ResultData}" DataContext="{Binding }" Grid.Row="6"
GroupByAreaLocation="None"
Width="Auto"
ActiveDataItem="{Binding SelectedItem}">
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Setter Property="Background" Value="White">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.CanBeCalculated}" Value="False">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Setter>
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DisplayImageCommand}"/>
</igDP:XamDataGrid.InputBindings>
error MC3015: The attached property 'Style.Triggers' is not defined on 'Setter' or one of its base classes.
错误 MC3015:附加属性“Style.Triggers”未在“Setter”或其基类之一上定义。
回答by Rohit Vats
Move the Style.Triggersout of Setterelement.
移动Style.Triggers出来的Setter元素。
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Setter Property="Background" Value="White"/> <-- HERE close the setter.
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},
Path=Record.DataItem.CanBeCalculated}" Value="False">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
回答by Gilad
this is the answer just putting it here for documentation thanks Rohit.
这是将它放在这里作为文档的答案,感谢 Rohit。
<igDP:XamDataGrid DataSource="{Binding ResultData}" DataContext="{Binding }" Grid.Row="6"
GroupByAreaLocation="None"
Width="Auto"
ActiveDataItem="{Binding SelectedItem}">
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:DataRecordCellArea}" BasedOn="{StaticResource {x:Type igDP:DataRecordCellArea}}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.CanBeCalculated}" Value="False">
<Setter Property="Background" Value="Tomato"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</igDP:XamDataGrid.Resources>

