1
我在App.xaml中定義的樣式如下:如何覆蓋XAML中的Datagrid單元格樣式?
<Style TargetType="DataGridCell">
<Setter Property= "BorderThickness" Value="1"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Grid Height="18">
<Border BorderBrush="Black" BorderThickness=".2" >
<Border x:Name="border" Background="#992288ff" BorderBrush="Black" BorderThickness=".2">
......
......
......
</Border>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
在我的形式,我有一個小區定義的風格。代碼如下:
<DataGridTextColumn Width="*" Header="Status" Binding="{Binding Status, Mode=TwoWay}" IsReadOnly="True" >
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Foreground">
<Setter.Value>
<Binding Converter="{StaticResource FGColorKey}"/>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
這裏我只定義了前景風格。但是我在app.xaml中爲單元格模板定義的樣式不適用於此單元格。請參閱下面的圖片附:
我一直在尋找答案..謝謝:) – sony