你可以在创建一个样式像这样的样本,以突出和调整我:
<!-- Right Aligned Cell -->
<Style x:Key="RightAlignedCell" TargetType="{x:Type dg:DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dg:DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="dg:DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="#356815" />
<Setter Property="Foreground" Value="#e2fce2" />
</Trigger>
</Style.Triggers>
</Style>
<!-- Center Aligned Cell -->
<Style x:Key="CenterAlignedCell" TargetType="{x:Type dg:DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dg:DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="dg:DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="#356815" />
<Setter Property="Foreground" Value="#e2fce2" />
</Trigger>
</Style.Triggers>
</Style>
后来你把:
<dg:DataGrid x:Name="dg" AutoGenerateColumns="False"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" ItemsSource="{Binding}"
SelectionMode="Single" ...>
<dg:DataGridTextColumn Header="Total Amount" Width="110" CellStyle="{StaticResource RightAlignedCell}"
Binding="{Binding Total,StringFormat={}\{0:N0\}}" IsReadOnly="True"/>
<dg:DataGridTextColumn Header="Enter Date" Width="110" CellStyle="{StaticResource CenterAlignedCell}"
Binding="{Binding EnterDate,StringFormat={}\{0:dd/MM/yyyy\}}" IsReadOnly="True"/>
....
我希望这个作品的人谁的徘徊如何突出在WPF数据网格中的整行。
你的建议的工作,但我有一个问题。我定义DataGridCell一个通用触发(例如设置不同的背景,如果它是只读)。然而,这个通用触发好像没有,如果我申请的RightAlignedCell样式而不触发工作。向你的风格添加触发器(就像你在这里所做的那样)工作正常。你能解释为什么吗? – newman 2011-05-15 17:34:44