【发布时间】:2017-11-24 19:29:09
【问题描述】:
我的 XAML 中有一个代码:检查条件时,目标行将为橙色。
这是 XAML.cs 中的代码:
private void DataGrid_Loaded(object sender, RoutedEventArgs e)
{
foreach (TrainOrdersClass item in dgBaseProd.ItemsSource)
{
var row = dgBaseProd.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
if ((item.IsOverFilled == true) || (item.IsOverWeighed == true))
{
row.Background = Brushes.Orange;
}
}
}
问题是当我点击 DataGrid 的标题时,所有颜色都消失了!
Xaml:
<DataGrid Name="DataGrid" AutoGenerateColumns="False"
Height="Auto" Width="780" Margin="10,10,10,10"
IsReadOnly="True" ItemsSource="{Binding Path=PreloadedRailcarstList}"
SelectedItem="{Binding Path=BaseProductToUpdate}"
AlternationCount="2" AlternatingRowBackground="LightBlue" Loaded="DataGrid_Loaded" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding Path=DataContext.OpenUpdateBaseProductViewCmd , RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding BaseProductToUpdate.name}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewKeyDown">
<i:InvokeCommandAction Command="{Binding Path=DataContext.OpenUpdateBaseProductViewCmd , RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding BaseProductToUpdate.name}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
//..
我该如何解决? 谢谢,
【问题讨论】:
-
你为什么不发布一些代码?
-
对不起,代码都是正确的,因为我没有发布
标签: c# wpf datagrid code-behind