Hi,
I have a ListView with its View set to a GridView, with some GridViewColumns defined. Basically I want it to look like a normal ListView on windows 7.
Unfortunately, even on windows 7 itself, the default colors of the selection highlights are slightly wrong. Furthermore I also want the ListView to look like a windows 7 ListView when not running on windows 7. Long story short: I want to supply a custom style to the items to get them to look like the windows 7 items.
This is the XAML and how the listview looks without any styling applied (on windows 7):
The colors look way different in my opinion:Code:<ListView ItemsSource="{Binding Series.ServiceSeries.Weeks}"> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header="" DisplayMemberBinding="{Binding WeekNumber}" /> <GridViewColumn Header="Start date" DisplayMemberBinding="{Binding Path=., Converter={StaticResource WeekConverter}, ConverterParameter=start}" /> <GridViewColumn Header="Track" DisplayMemberBinding="{Binding Path=., Converter={StaticResource WeekConverter}, ConverterParameter=track}" /> <GridViewColumn Header="Race length" DisplayMemberBinding="{Binding Path=., Converter={StaticResource WeekConverter}, ConverterParameter=length}" /> </GridView.Columns> </GridView> </ListView.View> </ListView>
As soon as I add an ItemContainerStyle however, the listview looks like this:
As you can see, the colors now match the windows 7 style much better, but the GridView look has disappeared and instead of using the columns, the objects are just shown by their string representation (which I did not implement, so it shows the full type name).
This is the style (omitted the colors for brevity, if you really want them I can add them):
Code:<Style TargetType="{x:Type ListViewItem}" x:Key="ListViewItemStyle"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Border x:Name="Border" CornerRadius="3" BorderThickness="1" SnapsToDevicePixels="True"> <Border x:Name="InnerBorder" CornerRadius="2" BorderBrush="Transparent" Background="Transparent" BorderThickness="1" Padding="3,1" SnapsToDevicePixels="True"> <ContentPresenter /> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource ListboxItemHoverBorder}" /> <Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource ListboxItemHoverInnerBorder}" /> <Setter TargetName="InnerBorder" Property="Background" Value="{StaticResource ListboxItemHoverBackground}" /> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource ListboxItemSelectedBorder}" /> <Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource ListboxItemSelectedInnerBorder}" /> <Setter TargetName="InnerBorder" Property="Background" Value="{StaticResource ListboxItemSelectedBackground}" /> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true" /> <Condition Property="Selector.IsSelectionActive" Value="false" /> </MultiTrigger.Conditions> <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource ListboxItemInactiveBorder}" /> <Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource ListboxItemInactiveInnerBorder}" /> <Setter TargetName="InnerBorder" Property="Background" Value="{StaticResource ListboxItemInactiveBackground}" /> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Any idea's what could cause this? How should I apply this style properly? The style is actually exactly the same as the style I'm using for a ListBox, (except the target type set to ListBoxItem), and I did this because some samples online did the same thing and it seemed to work for them...
Thanks!




Reply With Quote