We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to override style regardless of current theme?

I have a grid where I want all buttons to have a certain margin. All other style properties should be as if no custom style was applied, i.e. the still from the currently applied Theme.

Using something like below code doesn't work, as it completely ignores the theme's style.

    <Grid.Resources>
        <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
            <Style.Setters>
                <Setter Property="Margin" Value="3" />
            </Style.Setters>
        </Style>
    </Grid.Resources>

Resources such as http://help.syncfusion.com/ug/wpf/index.html#!documents/overridesyncfusionthemes.htm show how to override one specific style. This is far too complicated for me, since I'd need to 
1) include all possible themes
2) override each of these theme's style, all in the exact same manner
3) use code-behind to determine which theme is currently applied, and select the style based on this

Is there really no easier way to achieve this?

7 Replies

MA Muthukumar A Syncfusion Team July 30, 2015 11:46 AM UTC

Hi Soon,

Thanks for contacting Syncfusion.

In order to override theme from package you should override specific Style key provided in package.

Instead of BasedOn="{StaticResource {x:Type Button}}" ,
please use   BasedOn="{StaticResource MetroButtonStyle}"

Here, MetroButtonStyle is the key provided in Source. The naming convention of Style key is,

Themename+ControlName+ Style. For example MetroDateTimeEditStyle.

We have created a simple sample for this, and please have it from following location

Sample link: 
SkinSample_119772


Please let us know in case of any further assistance.

Regards,
Muthukumar A


SH Soon Hui Ngu July 31, 2015 12:52 AM UTC

The point of my question is that I don't want to override one specific style; I want the user to be able to select a theme and the override to be applied to whichever style is associated with this theme.


SM Sugapriya Mariappan Syncfusion Team July 31, 2015 10:07 AM UTC

Hi Soon,

We have modified our last updated sample which tries to meet your requirement. In this sample we have added the theming Dictionary for the Button control into the application to acquire all the properties of the base style and then we have overrided each style using BasedOn Property. And also based on theme selection at the runtime, overrided style for the corresponding theme will be applied.

Please download the sample from the following link
Sample link:SkinSample_119772

Please let us know if you need any other assistance

Regards,
M.Sugapriya


EG Eric Gurney August 10, 2017 04:28 PM UTC

How would I accomplish the same thing using SfSkinManager themes?

Thanks,

Eric




VI Vinothini Syncfusion Team August 11, 2017 07:27 AM UTC

Hi Eric, 
 
You requirement can be accomplished by using Theme studio. In ThemeStudio, you can customize the color of the predefined themes and export your customized themes for your application. The user guide for Theme Studio is available in the below link. 
 
 
Check with the above link and let us know if you need any further assistance. 
 
Regards, 
Vinothini.R 



EG Eric Gurney August 16, 2017 12:07 AM UTC

The merge and export exports a very small XAML file with hardly anything in it.  How do I get the same xaml pieces I see when I don't have that checked into one file?



VI Vinothini Syncfusion Team August 16, 2017 09:26 AM UTC

Hi Eric, 
 
Thank you for your update. 
 
We faced some problem in “Merge and Export” and it is fixed internally. A support incident has been created under your account to provide you the solution. Please log on to our support website to check for further updates.  
 
   
Regards, 
Vinothini.R 


Loader.
Live Chat Icon For mobile
Up arrow icon