你可以在創建一個樣式像這樣的樣本,以突出和調整我:
<!-- 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