0
我有一個像這樣應用於ListBoxItems的XAML DataTemplate。注意靠近底部的網格。我想要做的是根據文本的值改變綁定文本的顏色,如'Status:ERROR',其中'ERROR'爲紅色。如何從代碼隱藏中更改DataTemplate中的字體顏色?
<DataTemplate x:Key="ItemTemplate">
<Border BorderBrush="Gray" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FFA9A9A9" Offset="1.0"/>
<GradientStop Color="#FFF4F4F5" Offset="0.0"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Label Content="{Binding Name}" FontSize="22" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"/>
<Rectangle Grid.Row="1" Grid.Column="0" Grid.RowSpan="3">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FFF0F0F1" Offset="1.0"/>
<GradientStop Color="#FFF4F4F5" Offset="0.0"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Grid Grid.Row="1" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label Content="Status:"/>
<Label Content="{Binding Status}" Grid.Column="1"/>
</Grid>
<Label Content="{Binding Bookmark}" ContentStringFormat="Last Bookmark: {0}" Grid.Row="3" Grid.Column="0"/>
</Grid>
</Border>
</DataTemplate>
如何更改文本文字的顏色從後面的代碼(C#),其綁定狀態<Label>
? (或者,如果不是來自後面的代碼,如何在XAML?Status中可以有3個文本值(排隊,運行和錯誤),並且每個都與指定顏色(藍色,綠色和紅色)相匹配)
使用'
SLaks