【发布时间】:2017-02-16 16:57:19
【问题描述】:
我是 WPF 新手,我有以下用于列表视图的 xaml 代码:
<ListView x:Name="listView1" ItemsSource="{Binding Processes1}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="470" Margin="10,95,150,6" Width="565" SelectionChanged="NetscalerCfgView_listView1_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Header="Line" DisplayMemberBinding="{Binding srcCfgLineNum}"/>
<GridViewColumn Header="Source Config" DisplayMemberBinding="{Binding srcConfigText}"/>
</GridView>
</ListView.View>
</ListView>
我有我在列表视图中显示的类 SrcListViewInfo:
public class SrcListViewInfo
{
public int srcCfgLineNum { get; set; }
public string srcConfigText { get; set; }
}
我已经在 Windows 加载事件中声明它是这样的:
public ObservableCollection<SrcListViewInfo> processes1 = null;
processes1 = new ObservableCollection<SrcListViewInfo>();
我想在不同的情况下在不同的函数中动态给行背景动态上色,例如:
case DiffResultSpanStatus.DeleteSource:
for (i = 0; i < drs.Length; i++)
{
SrcListViewInfo newInfo = new SrcListViewInfo();
newInfo.BackgroundColor = new SolidColorBrush(Colors.Red);
// newInfo.BackgroundColor = Brushes.Red;
newInfo.srcCfgLineNum = cnt;
newInfo.srcConfigText = ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line;
// newInfo.BackgroundColor = Brushes.Red; << want to set the color like this.
我尝试过实体刷,但它似乎无法正常工作。
【问题讨论】:
标签: wpf