Theme support

Aug 26, 2013 at 9:11 AM
Hi Mike,
i downloaded your code to make a small fix to better support VS Theme, so i end up with this resource dictionary
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mtcw="clr-namespace:Microsoft.TeamFoundation.Controls.WPF;assembly=Microsoft.TeamFoundation.Controls"
                    xmlns:local="clr-namespace:Microsoft.ALMRangers.Samples.MyHistory" >

    <!-- Theme Indipendent Colors -->
    <SolidColorBrush x:Key="ItemBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemTextBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemTextColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemBorderBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemBorderColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemSelectedBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemSelectedColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemSelectedTextBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemSelectedTextColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemSelectedBorderBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemSelectedBorderColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemSelectedNotFocusedBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemSelectedNotFocusedColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemSelectedTextNotFocusedBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemSelectedTextNotFocusedColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemSelectedBorderNotFocusedBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemSelectedBorderNotFocusedColor,Mode=OneWay}" />
    <LinearGradientBrush x:Key="ItemHoverBrushKey" LinearGradientBrush.StartPoint="0.0,0.0" LinearGradientBrush.EndPoint="0.0,1.0">
        <GradientBrush.GradientStops>
            <GradientStop Offset="0.0" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemHoverGradientStartColor,Mode=OneWay}" />
            <GradientStop Offset="1.0" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemHoverGradientEndColor,Mode=OneWay}" />
        </GradientBrush.GradientStops>
    </LinearGradientBrush>
    <SolidColorBrush x:Key="ItemHoverTextBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemHoverTextColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="ItemHoverBorderBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=ItemHoverBorderColor,Mode=OneWay}" />
    <SolidColorBrush x:Key="SubduedTextBrushKey" Color="{Binding Source={x:Static mtcw:TeamFoundationColors.Instance},Path=SubduedTextColor,Mode=OneWay}" />


    <!-- ListViewItem Style -->
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Control.Background" Value="{StaticResource ItemBrushKey}" />
        <Setter Property="Control.Foreground" Value="{StaticResource ItemTextBrushKey}" />
        <Setter Property="Control.BorderBrush" Value="{StaticResource ItemBorderBrushKey}" />
        <Setter Property="Control.BorderThickness" Value="1" />
        <Setter Property="Control.HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="Control.VerticalContentAlignment" Value="{Binding VerticalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="Control.Padding" Value="0" />
        <Setter Property="FrameworkElement.Margin" Value="0" />
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate ControlTemplate.TargetType="{x:Type ListViewItem}">
                    <Border Border.Name="Bd" UIElement.SnapsToDevicePixels="True" Border.Background="{StaticResource ItemBrushKey}" TextElement.Foreground="{StaticResource ItemTextBrushKey}" Border.BorderBrush="{StaticResource ItemBorderBrushKey}" Border.BorderThickness="{TemplateBinding Control.BorderThickness}" Border.Padding="{TemplateBinding Control.Padding}" FrameworkElement.Margin="{TemplateBinding FrameworkElement.Margin}">
                        <GridViewRowPresenter GridViewRowPresenter.Content="{TemplateBinding ContentControl.Content}" GridViewRowPresenterBase.Columns="{TemplateBinding GridView.ColumnCollection}" UIElement.SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Trigger.Property="ListBoxItem.IsSelected" Trigger.Value="True">
                            <Setter TargetName="Bd" Value="{StaticResource ItemSelectedBrushKey}" Property="Border.Background" />
                            <Setter TargetName="Bd" Value="{StaticResource ItemSelectedTextBrushKey}" Property="TextElement.Foreground" />
                            <Setter TargetName="Bd" Value="{StaticResource ItemSelectedBorderBrushKey}" Property="Border.BorderBrush" />
                            <Setter Value="{StaticResource ItemSelectedBrushKey}" Property="Control.Background" />
                            <Setter Value="{StaticResource ItemSelectedTextBrushKey}" Property="Control.Foreground" />
                            <Setter Value="{StaticResource ItemSelectedBorderBrushKey}" Property="Control.BorderBrush" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Condition.Property="ListBoxItem.IsSelected" Condition.Value="False" />
                                <Condition Condition.Property="UIElement.IsMouseOver" Condition.Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Bd" Value="{StaticResource ItemHoverBrushKey}" Property="Border.Background" />
                            <Setter TargetName="Bd" Value="{StaticResource ItemHoverTextBrushKey}" Property="TextElement.Foreground" />
                            <Setter TargetName="Bd" Value="{StaticResource ItemHoverBorderBrushKey}" Property="Border.BorderBrush" />
                            <Setter Value="{StaticResource ItemHoverBrushKey}" Property="Control.Background" />
                            <Setter Value="{StaticResource ItemHoverTextBrushKey}" Property="Control.Foreground" />
                            <Setter Value="{StaticResource ItemHoverBorderBrushKey}" Property="Control.BorderBrush" />
                        </MultiTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Condition.Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}" Condition.Value="true" />
                                <Condition Condition.Binding="{Binding RelativeSource={RelativeSource Self},Path=IsMouseOver}" Condition.Value="false" />
                                <Condition Condition.Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBox}},Path=IsKeyboardFocusWithin}" Condition.Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="Bd" Value="{StaticResource ItemSelectedNotFocusedBrushKey}" Property="Border.Background" />
                            <Setter TargetName="Bd" Value="{StaticResource ItemSelectedTextNotFocusedBrushKey}" Property="TextElement.Foreground" />
                            <Setter TargetName="Bd" Value="{StaticResource ItemSelectedBorderNotFocusedBrushKey}" Property="Border.BorderBrush" />
                            <Setter Value="{StaticResource ItemSelectedNotFocusedBrushKey}" Property="Control.Background" />
                            <Setter Value="{StaticResource ItemSelectedTextNotFocusedBrushKey}" Property="Control.Foreground" />
                            <Setter Value="{StaticResource ItemSelectedBorderNotFocusedBrushKey}" Property="Control.BorderBrush" />
                        </MultiDataTrigger>
                        <Trigger Trigger.Property="UIElement.IsEnabled" Trigger.Value="False">
                            <Setter TargetName="Bd" Value="{StaticResource SubduedTextBrushKey}" Property="TextElement.Foreground" />
                            <Setter Value="{StaticResource SubduedTextBrushKey}" Property="Control.Foreground" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Converters -->
    <local:ChangesetCommentConverter x:Key="ChangesetCommentConverter"/>
</ResourceDictionary>
All ListViewItem styles now can be based on this implicit style e.g
<ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                    ...
This make the highlight theme independent.
I can attach full code if you are interested.

Best Regards
Massimiliano
Coordinator
Oct 4, 2013 at 8:11 AM
Hi Massimiliano

The full code would be appreciated!

thanks

Mike
Coordinator
Oct 4, 2013 at 9:29 AM
Marked as answer by mikeFourie on 11/29/2013 at 4:53 AM