Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am developing a project in WPF
and has added a styling file in XAML in the app.xaml as

HTML
<application x:class="JIMS.App" xmlns:x="#unknown">
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="Home.xaml">
    <application.resources>        
        <resourcedictionary source="Skins/Style.xaml" />
    </application.resources>
</application>


and then in the Style.xaml as
HTML
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <resourcedictionary.mergeddictionaries>
        <resourcedictionary source="Brushes.xaml" />
        <resourcedictionary source="Button.xaml" />
        <resourcedictionary source="Controls.xaml" />        
    </resourcedictionary.mergeddictionaries>
</resourcedictionary>


For certain controls i have not used key in style and gave target as that control iteslf.. I want that style to be applied to all the controls in my project...

HTML
<Style TargetType="{x:Type TextBox}">
        <setter property="Height" value="25"></setter>
        <setter property="BorderBrush" value="#444444"></setter>
        <setter property="Margin" value="0,2,0,2"></setter>
    </Style>


but this style is not appling for all the controls in the Application even though i am able to see the style applied in the Visual Studio Designer window but no result in RunTIme
Posted

1 solution

Try to add a dummy default style in a dictionary, where you merge dictionaries.
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<resourcedictionary.mergeddictionaries>
<resourcedictionary source="Brushes.xaml" />
<resourcedictionary source="Button.xaml" />
<resourcedictionary source="Controls.xaml" />
</resourcedictionary.mergeddictionaries>
</resourcedictionary>

<style targettype="Control" basedon="{StaticResource {x:Type Control}}" />

This should work
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900