我为ListView设置了以下样式:
<Style TargetType="{x:Type ListViewItem}">
<!-- <Setter Property="IsSelected" Value="{Binding Path=Delta, Converter=}" /> -->
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="#000000"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Name="Border" Padding="2" SnapsToDevicePixels="true"
CornerRadius="4" Margin="0,4,0,0">
<GridViewRowPresenter VerticalAlignment="{TemplateBinding
VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" TargetName="Border"
Value="#A5FFFFFF"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" TargetName="Border"
Value="#01FFFFFF">
</Setter>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" TargetName="Border"
Value="#99B4C6"/>
<Setter Property="Foreground" Value="#000000"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Border"
Value="#c5d7e5"/>
<Setter Property="Foreground" Value="#000000"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#000000"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在强制量将使我的TextBlocks正确对齐并且如果我设置
<Setter Property="HorizontalContentAlignment" Value="Right" />
在我的风格中,我会遇到相反的问题。我这样定义我的模板:
<GridViewColumn Header="Bid Price">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextAlignment="Right" HorizontalAlignment="Right"
Text="{Binding Path=BidPx, StringFormat='{}{0:C}'}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>