TreeViewItem selected background color not updating

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 4 months 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 4 months ago]

Comments (2)

Posted 4 months ago by Michael Janulaitis - Corner Bowl Software
Avatar

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

Posted 4 months 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 (v22.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.