我有这门课:
public class ShippingMethodMap
{
public string ShippingMethod { get; set; }
public int? MethodId { get; set; }
public bool IsManaged { get; set; }
public bool IsValid { get; set; }
}
数据存储在ObservableCollection<ShippingMethodMap> ShippingMethodMapCollection
,并显示在XAML
类似
<ItemsControl ItemsSource="{Binding Path=ShippingMethodMapCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="1" BorderThickness="1" BorderBrush="LightGray">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{Binding Path=ShippingMethod}">
</TextBlock>
<TextBox Grid.Column="1"
Text="{Binding Path=MethodId}"
IsEnabled="{Binding Path=IsManaged}">
</TextBox>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
现在 - 如果 ShippingMethodMap.IsValid = false,我该如何将(不同项目的)前景色设置TextBlock
为TextBox
红色?
您可以将默认的 TextBlock 和 TextBox 样式添加到
DataTrigger
边框的资源中: