<p>In WPF, how would I apply multiple styles to a <code>FrameworkElement</code>?  For instance, I have a control which already has a style.  I also have a separate style which I would like to add to it without blowing away the first one.  The styles have different TargetTypes, so I can't just extend one with the other.</p>

[{'answer_id': 16108, 'author': 'Arcturus', 'author_id': 900, 'author_profile': 'https://Stackoverflow.com/users/900', 'pm_score': 5, 'selected': False, 'text': '<p>But you can extend from another.. take a look at the BasedOn property</p>\n\n<pre><code>&lt;Style TargetType="TextBlock"&gt;\n      &lt;Setter Property="Margin" Value="3" /&gt;\n&lt;/Style&gt;\n\n&lt;Style x:Key="AlwaysVerticalStyle" TargetType="TextBlock" \n       BasedOn="{StaticResource {x:Type TextBlock}}"&gt;\n     &lt;Setter Property="VerticalAlignment" Value="Top" /&gt;\n&lt;/Style&gt;\n</code></pre>\n'}, {'answer_id': 69379, 'author': 'Greg', 'author_id': 11013, 'author_profile': 'https://Stackoverflow.com/users/11013', 'pm_score': 1, 'selected': False, 'text': "<p>if you are not touching any specific properties, you can get all base and common properties to the style which's target type would be FrameworkElement. then, you can create specific flavours for each target types you need, without need of copying all those common properties again.</p>\n"}, {'answer_id': 167308, 'author': 'cplotts', 'author_id': 22294, 'author_profile': 'https://Stackoverflow.com/users/22294', 'pm_score': 8, 'selected': True, 'text': '<p><strong>I think the simple answer is that you can\'t do (at least in this version of WPF) what you are trying to do.</strong></p>\n\n<p><em>That is, for any particular element only one Style can be applied.</em></p>\n\n<p>However, as others have stated above, maybe you can use <code>BasedOn</code> to help you out. Check out the following piece of loose xaml. In it you will see that I have a base style that is setting a property that exists on the base class of the element that I want to apply two styles to. And, in the second style which is based on the base style, I set another property.</p>\n\n<p><strong>So, the idea here ... is if you can somehow separate the properties that you want to set ... according the inheritance hierarchy of the element you want to set multiple styles on ... you might have a workaround.</strong></p>\n\n<pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;\n    &lt;Page.Resources&gt;\n        &lt;Style x:Key="baseStyle" TargetType="FrameworkElement"&gt;\n            &lt;Setter Property="HorizontalAlignment" Value="Left"/&gt;\n        &lt;/Style&gt;\n        &lt;Style TargetType="Button" BasedOn="{StaticResource baseStyle}"&gt;\n            &lt;Setter Property="Content" Value="Hello World"/&gt;\n        &lt;/Style&gt;\n    &lt;/Page.Resources&gt;\n    &lt;Grid&gt;\n        &lt;Button Width="200" Height="50"/&gt;\n    &lt;/Grid&gt;\n&lt;/Page&gt;\n</code></pre>\n\n<p><br>\nHope this helps.</p>\n\n<p><strong>Note:</strong></p>\n\n<p>One thing in particular to note. If you change the <code>TargetType</code> in the second style (in first set of xaml above) to <code>ButtonBase</code>, the two Styles do not get applied. However, check out the following xaml below to get around that restriction. Basically, it means you need to give the Style a key and reference it with that key.</p>\n\n<pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;\n    &lt;Page.Resources&gt;\n        &lt;Style x:Key="baseStyle" TargetType="FrameworkElement"&gt;\n            &lt;Setter Property="HorizontalAlignment" Value="Left"/&gt;\n        &lt;/Style&gt;\n        &lt;Style x:Key="derivedStyle" TargetType="ButtonBase" BasedOn="{StaticResource baseStyle}"&gt;\n            &lt;Setter Property="Content" Value="Hello World"/&gt;\n        &lt;/Style&gt;\n    &lt;/Page.Resources&gt;\n    &lt;Grid&gt;\n        &lt;Button Width="200" Height="50" Style="{StaticResource derivedStyle}"/&gt;\n    &lt;/Grid&gt;\n&lt;/Page&gt;\n</code></pre>\n'}, {'answer_id': 204311, 'author': 'Dave', 'author_id': 28197, 'author_profile': 'https://Stackoverflow.com/users/28197', 'pm_score': 1, 'selected': False, 'text': '<p>You can probably get something similar if applying this to a collection of items by the use of a StyleSelector, i have used this to approach a similar problem in using different styles on TreeViewItems depending on the bound object type in the tree. You may have to modify the class below slightly to adjust to your particular approach but hopefully this will get you started</p>\n\n<pre><code>public class MyTreeStyleSelector : StyleSelector\n{\n    public Style DefaultStyle\n    {\n        get;\n        set;\n    }\n\n    public Style NewStyle\n    {\n        get;\n        set;\n    }\n\n    public override Style SelectStyle(object item, DependencyObject container)\n    {\n        ItemsControl ctrl = ItemsControl.ItemsControlFromItemContainer(container);\n\n        //apply to only the first element in the container (new node)\n        if (item == ctrl.Items[0])\n        {\n            return NewStyle;\n        }\n        else\n        {\n            //otherwise use the default style\n            return DefaultStyle;\n        }\n    }\n}\n</code></pre>\n\n<p>You then apply this as so</p>\n\n<pre>\n &lt;TreeView&gt;\n     &lt;TreeView.ItemContainerStyleSelector\n         &lt;myassembly:MyTreeStyleSelector DefaultStyle="{StaticResource DefaultItemStyle}"\n                                         NewStyle="{StaticResource NewItemStyle}" /&gt;\n     &lt;/TreeView.ItemContainerStyleSelector&gt;\n  &lt;/TreeView&gt;\n</pre>\n'}, {'answer_id': 410430, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>WPF/XAML doesn\'t provide this functionality natively, but it does provide the extensibility to allow you to do what you want.</p>\n\n<p>We ran into the same need, and ended up creating our own XAML Markup Extension (which we called "MergedStylesExtension") to allow us to create a new Style from two other styles (which, if needed, could probably be used multiple times in a row to inherit from even more styles).</p>\n\n<p>Due to a WPF/XAML bug, we need to use property element syntax to use it, but other than that it seems to work ok.  E.g.,</p>\n\n<pre><code>&lt;Button\n    Content="This is an example of a button using two merged styles"&gt;\n    &lt;Button.Style&gt;\n      &lt;ext:MergedStyles\n                BasedOn="{StaticResource FirstStyle}"\n                MergeStyle="{StaticResource SecondStyle}"/&gt;\n   &lt;/Button.Style&gt;\n&lt;/Button&gt;\n</code></pre>\n\n<p>I recently wrote about it here:\n<a href="http://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/" rel="noreferrer">http://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/</a></p>\n'}, {'answer_id': 1866600, 'author': 'Wilka', 'author_id': 1367, 'author_profile': 'https://Stackoverflow.com/users/1367', 'pm_score': 6, 'selected': False, 'text': '<p>Bea Stollnitz had <a href="http://web.archive.org/web/20101125040337/http://bea.stollnitz.com/blog/?p=384" rel="nofollow noreferrer">a good blog post</a> about using a markup extension for this, under the heading &quot;How can I set multiple styles in WPF?&quot;</p>\n<p>That blog is dead now, so I\'m reproducing the post here:</p>\n<blockquote>\n<p>WPF and Silverlight both offer the ability to derive a Style from\nanother Style through the “BasedOn” property. This feature enables\ndevelopers to organize their styles using a hierarchy similar to class\ninheritance. Consider the following styles:</p>\n<pre class="lang-xml prettyprint-override"><code>&lt;Style TargetType=&quot;Button&quot; x:Key=&quot;BaseButtonStyle&quot;&gt;\n    &lt;Setter Property=&quot;Margin&quot; Value=&quot;10&quot; /&gt;\n&lt;/Style&gt;\n&lt;Style TargetType=&quot;Button&quot; x:Key=&quot;RedButtonStyle&quot; BasedOn=&quot;{StaticResource BaseButtonStyle}&quot;&gt;\n    &lt;Setter Property=&quot;Foreground&quot; Value=&quot;Red&quot; /&gt;\n&lt;/Style&gt;\n</code></pre>\n<p>With this syntax, a Button that uses RedButtonStyle will have its\nForeground property set to Red and its Margin property set to 10.</p>\n<p>This feature has been around in WPF for a long time, and it’s new in\nSilverlight 3.</p>\n<p>What if you want to set more than one style on an element? Neither WPF\nnor Silverlight provide a solution for this problem out of the box.\nFortunately there are ways to implement this behavior in WPF, which I\nwill discuss in this blog post.</p>\n<p>WPF and Silverlight use markup extensions to provide properties with\nvalues that require some logic to obtain. Markup extensions are easily\nrecognizable by the presence of curly brackets surrounding them in\nXAML. For example, the {Binding} markup extension contains logic to\nfetch a value from a data source and update it when changes occur; the\n{StaticResource} markup extension contains logic to grab a value from\na resource dictionary based on a key. Fortunately for us, WPF allows\nusers to write their own custom markup extensions. This feature is not\nyet present in Silverlight, so the solution in this blog is only\napplicable to WPF.</p>\n<p><a href="https://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/" rel="nofollow noreferrer">Others</a>\nhave written great solutions to merge two styles using markup\nextensions. However, I wanted a solution that provided the ability to\nmerge an unlimited number of styles, which is a little bit trickier.</p>\n<p>Writing a markup extension is straightforward. The first step is to\ncreate a class that derives from MarkupExtension, and use the\nMarkupExtensionReturnType attribute to indicate that you intend the\nvalue returned from your markup extension to be of type Style.</p>\n<pre class="lang-cs prettyprint-override"><code>[MarkupExtensionReturnType(typeof(Style))]\npublic class MultiStyleExtension : MarkupExtension\n{\n}\n</code></pre>\n<h3>Specifying inputs to the markup extension</h3>\n<p>We’d like to give users of our markup extension a simple way to\nspecify the styles to be merged. There are essentially two ways in\nwhich the user can specify inputs to a markup extension. The user can\nset properties or pass parameters to the constructor. Since in this\nscenario the user needs the ability to specify an unlimited number of\nstyles, my first approach was to create a constructor that takes any\nnumber of strings using the “params” keyword:</p>\n<pre class="lang-cs prettyprint-override"><code>public MultiStyleExtension(params string[] inputResourceKeys)\n{\n}\n</code></pre>\n<p>My goal was to be able to write the inputs as follows:</p>\n<pre class="lang-cs prettyprint-override"><code>&lt;Button Style=&quot;{local:MultiStyle BigButtonStyle, GreenButtonStyle}&quot; … /&gt;\n</code></pre>\n<p>Notice the comma separating the different style keys. Unfortunately,\ncustom markup extensions don’t support an unlimited number of\nconstructor parameters, so this approach results in a compile error.\nIf I knew in advance how many styles I wanted to merge, I could have\nused the same XAML syntax with a constructor taking the desired number\nof strings:</p>\n<pre class="lang-cs prettyprint-override"><code>public MultiStyleExtension(string inputResourceKey1, string inputResourceKey2)\n{\n}\n</code></pre>\n<p>As a workaround, I decided to have the constructor parameter take a\nsingle string that specifies the style names separated by spaces. The\nsyntax isn’t too bad:</p>\n<p>&lt;Button Style=&quot;{local:MultiStyle BigButtonStyle GreenButtonStyle}&quot;\n… /&gt;</p>\n<pre class="lang-cs prettyprint-override"><code>private string[] resourceKeys;\n\npublic MultiStyleExtension(string inputResourceKeys)\n{\n    if (inputResourceKeys == null)\n    {\n        throw new ArgumentNullException(&quot;inputResourceKeys&quot;);\n    }\n\n    this.resourceKeys = inputResourceKeys.Split(new char[] { \' \' }, StringSplitOptions.RemoveEmptyEntries);\n\n    if (this.resourceKeys.Length == 0)\n    {\n        throw new ArgumentException(&quot;No input resource keys specified.&quot;);\n    }\n}\n</code></pre>\n<h3>Calculating the output of the markup extension</h3>\n<p>To calculate the output of a markup extension, we need to override a\nmethod from MarkupExtension called “ProvideValue”. The value returned\nfrom this method will be set in the target of the markup extension.</p>\n<p>I started by creating an extension method for Style that knows how to\nmerge two styles. The code for this method is quite simple:</p>\n<pre class="lang-cs prettyprint-override"><code>public static void Merge(this Style style1, Style style2)\n{\n    if (style1 == null)\n    {\n        throw new ArgumentNullException(&quot;style1&quot;);\n    }\n    if (style2 == null)\n    {\n        throw new ArgumentNullException(&quot;style2&quot;);\n    }\n\n    if (style1.TargetType.IsAssignableFrom(style2.TargetType))\n    {\n        style1.TargetType = style2.TargetType;\n    }\n\n    if (style2.BasedOn != null)\n    {\n        Merge(style1, style2.BasedOn);\n    }\n\n    foreach (SetterBase currentSetter in style2.Setters)\n    {\n        style1.Setters.Add(currentSetter);\n    }\n\n    foreach (TriggerBase currentTrigger in style2.Triggers)\n    {\n        style1.Triggers.Add(currentTrigger);\n    }\n\n    // This code is only needed when using DynamicResources.\n    foreach (object key in style2.Resources.Keys)\n    {\n        style1.Resources[key] = style2.Resources[key];\n    }\n}\n</code></pre>\n<p>With the logic above, the first style is modified to include all\ninformation from the second. If there are conflicts (e.g. both styles\nhave a setter for the same property), the second style wins. Notice\nthat aside from copying styles and triggers, I also took into account\nthe TargetType and BasedOn values as well as any resources the second\nstyle may have. For the TargetType of the merged style, I used\nwhichever type is more derived. If the second style has a BasedOn\nstyle, I merge its hierarchy of styles recursively. If it has\nresources, I copy them over to the first style. If those resources are\nreferred to using {StaticResource}, they’re statically resolved before\nthis merge code executes, and therefore it isn’t necessary to move\nthem. I added this code in case we’re using DynamicResources.</p>\n<p>The extension method shown above enables the following syntax:</p>\n<pre class="lang-cs prettyprint-override"><code>style1.Merge(style2);\n</code></pre>\n<p>This syntax is useful provided that I have instances of both styles\nwithin ProvideValue. Well, I don’t. All I get from the constructor is\na list of string keys for those styles. If there was support for\nparams in the constructor parameters, I could have used the following\nsyntax to get the actual style instances:</p>\n<pre class="lang-xml prettyprint-override"><code>&lt;Button Style=&quot;{local:MultiStyle {StaticResource BigButtonStyle}, {StaticResource GreenButtonStyle}}&quot; … /&gt;\n</code></pre>\n<pre class="lang-cs prettyprint-override"><code>public MultiStyleExtension(params Style[] styles)\n{\n}\n</code></pre>\n<p>But that doesn’t work. And even if the params limitation didn’t exist,\nwe would probably hit another limitation of markup extensions, where\nwe would have to use property-element syntax instead of attribute\nsyntax to specify the static resources, which is verbose and\ncumbersome (I explain this bug better in a <a href="http://web.archive.org/web/20101125040337/http://www.beacosta.com/blog/?p=36" rel="nofollow noreferrer">previous blog\npost</a>).\nAnd even if both those limitations didn’t exist, I would still rather\nwrite the list of styles using just their names – it is shorter and\nsimpler to read than a StaticResource for each one.</p>\n<p>The solution is to create a StaticResourceExtension using code. Given\na style key of type string and a service provider, I can use\nStaticResourceExtension to retrieve the actual style instance. Here is\nthe syntax:</p>\n<pre class="lang-cs prettyprint-override"><code>Style currentStyle = new StaticResourceExtension(currentResourceKey).ProvideValue(serviceProvider)\n</code></pre>\n<p>as Style;</p>\n<p>Now we have all the pieces needed to write the ProvideValue method:</p>\n<pre class="lang-cs prettyprint-override"><code>public override object ProvideValue(IServiceProvider serviceProvider)\n{\n    Style resultStyle = new Style();\n\n    foreach (string currentResourceKey in resourceKeys)\n    {\n        Style currentStyle = new StaticResourceExtension(currentResourceKey).ProvideValue(serviceProvider)\n</code></pre>\n<p>as Style;</p>\n<pre><code>        if (currentStyle == null)\n        {\n            throw new InvalidOperationException(&quot;Could not find style with resource key &quot; + currentResourceKey + &quot;.&quot;);\n        }\n\n        resultStyle.Merge(currentStyle);\n    }\n    return resultStyle;\n}\n</code></pre>\n<p>Here is a complete example of the usage of the MultiStyle markup\nextension:</p>\n<pre class="lang-xml prettyprint-override"><code>&lt;Window.Resources&gt;\n    &lt;Style TargetType=&quot;Button&quot; x:Key=&quot;SmallButtonStyle&quot;&gt;\n        &lt;Setter Property=&quot;Width&quot; Value=&quot;120&quot; /&gt;\n        &lt;Setter Property=&quot;Height&quot; Value=&quot;25&quot; /&gt;\n        &lt;Setter Property=&quot;FontSize&quot; Value=&quot;12&quot; /&gt;\n    &lt;/Style&gt;\n\n    &lt;Style TargetType=&quot;Button&quot; x:Key=&quot;GreenButtonStyle&quot;&gt;\n        &lt;Setter Property=&quot;Foreground&quot; Value=&quot;Green&quot; /&gt;\n    &lt;/Style&gt;\n\n    &lt;Style TargetType=&quot;Button&quot; x:Key=&quot;BoldButtonStyle&quot;&gt;\n        &lt;Setter Property=&quot;FontWeight&quot; Value=&quot;Bold&quot; /&gt;\n    &lt;/Style&gt;\n&lt;/Window.Resources&gt;\n\n&lt;Button Style=&quot;{local:MultiStyle SmallButtonStyle GreenButtonStyle BoldButtonStyle}&quot; Content=&quot;Small, green, bold&quot; /&gt;\n</code></pre>\n<p><a href="https://i.stack.imgur.com/YTzpK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YTzpK.png" alt="enter image description here" /></a></p>\n</blockquote>\n'}, {'answer_id': 12730626, 'author': 'Shahar Prish', 'author_id': 594571, 'author_profile': 'https://Stackoverflow.com/users/594571', 'pm_score': 2, 'selected': False, 'text': '<p>This is possible by creating a helper class to use and wrap your styles. CompoundStyle mentioned <a href="http://socialeboladev.wordpress.com/2012/10/04/using-multiple-styles-on-elements-in-xaml-windows-8wp7/" rel="nofollow">here</a> shows how to do it. There are multiple ways, but the easiest is to do the following:</p>\n\n<pre><code>&lt;TextBlock Text="Test"\n    local:CompoundStyle.StyleKeys="headerStyle,textForMessageStyle,centeredStyle"/&gt;\n</code></pre>\n\n<p>Hope that helps.</p>\n'}, {'answer_id': 20179478, 'author': 'hillin', 'author_id': 1383540, 'author_profile': 'https://Stackoverflow.com/users/1383540', 'pm_score': 1, 'selected': False, 'text': "<p>Sometimes you can approach this by nesting panels. Say you have a Style which changes Foreground and another changes FontSize, you can apply the latter one on a TextBlock, and put it in a Grid which its Style is the first one. This might help and might be the easiest way in some cases, though it won't solve all the problems.</p>\n"}, {'answer_id': 21568120, 'author': 'Sérgio Henrique', 'author_id': 3273517, 'author_profile': 'https://Stackoverflow.com/users/3273517', 'pm_score': 1, 'selected': False, 'text': '<p>When you override SelectStyle you can get GroupBy property via reflection like below:</p>\n\n<pre><code>    public override Style SelectStyle(object item, DependencyObject container)\n    {\n\n        PropertyInfo p = item.GetType().GetProperty("GroupBy", BindingFlags.NonPublic | BindingFlags.Instance);\n\n        PropertyGroupDescription propertyGroupDescription = (PropertyGroupDescription)p.GetValue(item);\n\n        if (propertyGroupDescription != null &amp;&amp; propertyGroupDescription.PropertyName == "Title" )\n        {\n            return this.TitleStyle;\n        }\n\n        if (propertyGroupDescription != null &amp;&amp; propertyGroupDescription.PropertyName == "Date")\n        {\n            return this.DateStyle;\n        }\n\n        return null;\n    }\n</code></pre>\n'}, {'answer_id': 46163919, 'author': 'google dev', 'author_id': 7206675, 'author_profile': 'https://Stackoverflow.com/users/7206675', 'pm_score': 2, 'selected': False, 'text': '<p>Use <code>AttachedProperty</code> to set multiple styles like following code:</p>\n<pre><code>public static class Css\n{\n\n    public static string GetClass(DependencyObject element)\n    {\n        if (element == null)\n            throw new ArgumentNullException(&quot;element&quot;);\n\n        return (string)element.GetValue(ClassProperty);\n    }\n\n    public static void SetClass(DependencyObject element, string value)\n    {\n        if (element == null)\n            throw new ArgumentNullException(&quot;element&quot;);\n\n        element.SetValue(ClassProperty, value);\n    }\n\n\n    public static readonly DependencyProperty ClassProperty =\n        DependencyProperty.RegisterAttached(&quot;Class&quot;, typeof(string), typeof(Css), \n            new PropertyMetadata(null, OnClassChanged));\n\n    private static void OnClassChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\n    {\n        var ui = d as FrameworkElement;\n        Style newStyle = new Style();\n\n        if (e.NewValue != null)\n        {\n            var names = e.NewValue as string;\n            var arr = names.Split(new char[] { \' \' }, StringSplitOptions.RemoveEmptyEntries);\n            foreach (var name in arr)\n            {\n                Style style = ui.FindResource(name) as Style;\n                foreach (var setter in style.Setters)\n                {\n                    newStyle.Setters.Add(setter);\n                }\n                foreach (var trigger in style.Triggers)\n                {\n                    newStyle.Triggers.Add(trigger);\n                }\n            }\n        }\n        ui.Style = newStyle;\n    }\n}\n</code></pre>\n<p>Usage: (Point the <em>xmlns:local=&quot;clr-namespace:style_a_class_like_css&quot;</em> to the right namespace)</p>\n<pre><code>&lt;Window x:Class=&quot;MainWindow&quot;\n        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;\n        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;\n        xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;\n        xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;\n        xmlns:local=&quot;clr-namespace:style_a_class_like_css&quot;\n        mc:Ignorable=&quot;d&quot;\n        Title=&quot;MainWindow&quot; Height=&quot;150&quot; Width=&quot;325&quot;&gt;\n    &lt;Window.Resources&gt;\n\n        &lt;Style TargetType=&quot;TextBlock&quot; x:Key=&quot;Red&quot; &gt;\n            &lt;Setter Property=&quot;Foreground&quot; Value=&quot;Red&quot;/&gt;\n        &lt;/Style&gt;\n\n        &lt;Style TargetType=&quot;TextBlock&quot; x:Key=&quot;Green&quot; &gt;\n            &lt;Setter Property=&quot;Foreground&quot; Value=&quot;Green&quot;/&gt;\n        &lt;/Style&gt;\n        \n        &lt;Style TargetType=&quot;TextBlock&quot; x:Key=&quot;Size18&quot; &gt;\n            &lt;Setter Property=&quot;FontSize&quot; Value=&quot;18&quot;/&gt;\n            &lt;Setter Property=&quot;Margin&quot; Value=&quot;6&quot;/&gt;\n        &lt;/Style&gt;\n\n        &lt;Style TargetType=&quot;TextBlock&quot; x:Key=&quot;Bold&quot; &gt;\n            &lt;Setter Property=&quot;FontWeight&quot; Value=&quot;Bold&quot;/&gt;\n        &lt;/Style&gt;\n\n    &lt;/Window.Resources&gt;\n    &lt;StackPanel&gt;\n        \n        &lt;Button Content=&quot;Button&quot; local:Css.Class=&quot;Red Bold&quot; Width=&quot;75&quot;/&gt;\n        &lt;Button Content=&quot;Button&quot; local:Css.Class=&quot;Red Size18&quot; Width=&quot;75&quot;/&gt;\n        &lt;Button Content=&quot;Button&quot; local:Css.Class=&quot;Green Size18 Bold&quot; Width=&quot;75&quot;/&gt;\n\n    &lt;/StackPanel&gt;\n&lt;/Window&gt;\n</code></pre>\n<p>Result:</p>\n<p><a href="https://i.stack.imgur.com/255Jp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/255Jp.png" alt="enter image description here" /></a></p>\n'}, {'answer_id': 54497999, 'author': 'JamesHoux', 'author_id': 1402498, 'author_profile': 'https://Stackoverflow.com/users/1402498', 'pm_score': 0, 'selected': False, 'text': '<p><strong>If you are trying to apply a unique style to just one single element</strong> as an addition to a base style, there is a completely different way to do this that is IMHO much better for readable and maintainable code.</p>\n\n<p>It\'s extremely common to need to tweak parameters per individual element. Defining dictionary styles just for use on one-element is extremely cumbersome to maintain or make sense of. To avoid creating styles just for one-off element tweaks, read my answer to my own question here here:</p>\n\n<p><a href="https://stackoverflow.com/a/54497665/1402498">https://stackoverflow.com/a/54497665/1402498</a></p>\n'}]
['https://Stackoverflow.com/questions/16096', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/93/']