WPF and external CSS file
1 answer
It's not called CSS, but you can create a resource dictionary in a separate file like this:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MyStyledButton" TargetType="Button">
.
Put the details of your style here, just like you would for a normal style.
.
</Style>
</ResourceDictionary>
Then you can import the resource dictionary into other XAML files by setting the resources in the class, for example, if you have a Window class, you would do:
<Window.Resources>
<ResourceDictionary Source="MyStylesFile.xaml" />
</Window.Resources>
This style now takes effect for any control in the window, just as if you specified the style directly in the window resources.
+10
source to share