TreeViewItem selected background color not updating

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 2 years ago by Michael Janulaitis - Corner Bowl Software
Version: 22.1.0
Avatar

I have set the theme like so where color700string is some random color:

ThemeManager.BeginUpdate();
            try
            {
                ThemeManager.RegisterThemeDefinition(new ThemeDefinition("Custom")
                {
                    BaseColorBlue = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(color700String)
                });

                ThemeManager.AreNativeThemesEnabled = true;
                ThemeManager.CurrentTheme = "Custom";
            }
            finally
            {
                ThemeManager.EndUpdate();
            }

I have set the style like so:

    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
        <Setter Property="local:FocusExtension.IsFocused" Value="{Binding IsFocused, Mode=TwoWay}"/>
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />      
    </Style>

The background selected color for TreeViewItems found in TreeViews is always the system color.

[Modified 2 years ago]

Comments (2)

Posted 2 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

I have created my own template and all is good now.  Please delete this topic.

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

I replaced our Sample Browser's app startup code with your theme configuration logic and went to our Themes' Native Control Themes QuickStart sample.  I see the custom color showing properly in the background for TreeView items there, not the system color.

Perhaps you have a custom implicit Style for TreeViewItem in your app that is preventing our "themed" implicit Style from taking effect?  You said a custom template fixed it on your end.  FYI, WPF only allows a single default Style and a single implicit Style to be active at any time.  Using ThemeManager.AreNativeThemesEnabled injects our "themed" implicit Style, but that could be blocked if you are setting a Style too.  If you are setting a custom Style for the TreeViewItems, make sure you make it BasedOn ours like:

BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.TreeViewItemStyleKey}}"


Actipro Software Support

The latest build of this product (v24.1.2) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.