Overriding some native styles fails

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 6 years ago by Bjørnar Sundsbø - Norway
Version: 13.1.0582
Environment: Windows 8 (64-bit)
Avatar

Hi,

I need to change the style of some of the native controls, and for some reason I seem to fail to do so for some of the styles. ThemeManager.AreNativeThemesEnabled is set to true, and the ResourceDictionaries are included.

This works like a charm:

    <Style x:Key="{x:Static themes:SharedResourceKeys.TabItemStyleKey}" TargetType="{x:Type TabItem}">
        
    </Style>

    <Style x:Key="{x:Static themes:SharedResourceKeys.TabControlStyleKey}" TargetType="{x:Type TabControl}">
        
    </Style>

 

However, if I try to do this to ListBoxItem, it reverts back to the native style without the actipro touch, with any modifications I might add.

    <Style x:Key="{x:Static themes:SharedResourceKeys.ListBoxItemStyleKey}" TargetType="{x:Type ListBoxItem}">

    </Style>

Seems to be the same issue with ListBox. Haven't gotten around to doing the same to ListViewItem, etc. If I remove the "whole" style, actipro native style is used. I don't need to add any setters for the style to revert back to the native WPF style. There might be other styles that are affected in the same way, though i have not yet identified them

Any ideas?


Bjørnar Sundsbø

Comments (7)

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

Hi,

The safest thing to do for these scenarios is to inherit our native styles if you want to retain our look.  For instance, put this on the ListItem Style:

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


Actipro Software Support

Posted 6 years ago by Bjørnar Sundsbø - Norway
Avatar

I tried that too (should have said), but I got the same result.


Bjørnar Sundsbø

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

Perhaps the ListBox.ItemContainerStyle is getting altered to be something that isn't based on our styles?


Actipro Software Support

Posted 6 years ago by Bjørnar Sundsbø - Norway
Avatar

Everything is possible. If I remove the style completely from my resource dictionary, I get your style. Adding the override in the way I stated, or your way (event without setting any properties) gives me the default WPF style.


Bjørnar Sundsbø

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

If you'd like us to look into it further, please email our support address with a new simple sample project showing the issue.  Reference this post and rename the .zip file extension so it doesn't get spam blocked.


Actipro Software Support

Answer - Posted 6 years ago by Bjørnar Sundsbø - Norway
Avatar

Vacation is now over, and I have had time to look into it.

It appears that I had not included Includes\Common.xaml and Includes\Default.xaml from my Generic.xaml. All the styles worked that were included by Default.xaml, but it appears there was a problem applying actipro (at least native) styles to the controls properly. Seemed like actipro loaded whatever was in those two files so that my custom styles were applied, but it failed to apply the native styles. Perhaps a timing issue for when this is loaded?

With my previous approach (not including Common/Default), the styling "worked" without BasedOn (though with my previous problem). When I now include the files, I get the following warning/error "A loop was detected in the property expressions", which corresponds with the problem reported at StackOverflow. It works, but it is yet another warning that keeps annoying me. However, it doesn't seem to have anything to do with the Actipro controls.

As a bonus, adding the <ResourceDictionary Source="Includes\Default.xaml", etc also seemed to fix an issue I had where TextBlock did not get the correct Foreground based on the current theme (Foreground was not set as white for MetroDark).


Bjørnar Sundsbø

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

I don't think there are generally any timing issues for when things are loaded, assuming you are doing all this at app startup anyhow.  But the order in which you load resources into Application.Resources and when you set our themes could certainly have an effect.  Since if you set our theme first and load your resources programmatically afterward, it will likely cause your resources to override ours.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 15 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.