1. Add a resource dictionary file style.xmal
2. Add custom style in resource dictionary, etc.
<ResourceDictionaryxmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local= "Clr-namespace:wpftest.resources"> <Stylex:key= "For_noresize_window"TargetType="{x:type Window}"> <Setter Property= "AllowsTransparency"Value= "true"/> <Setter Property= "Background"Value= "Transparent"/> <Setter Property= "FontFamily"Value= "Consolas, Microsoft Yahei"/> <Setter Property= "ResizeMode"Value= "Noresize"/> <Setter Property= "WindowStyle"Value= "None"/> <Setter Property= "Template"> <Setter.value> <ControlTemplateTargetType="{x:type Window}"> <GridMargin= "Ten"> <RectangleFill="{dynamicresource {x:static Systemcolors.windowbrushkey}}"RadiusX= "5"RadiusY= "5"> <Rectangle.effect> <DropshadoweffectBlurradius= "Ten"shadowdepth= "0"/> </Rectangle.effect> </Rectangle> <BorderBackground="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"borderthickness="{TemplateBinding BorderThickness}"Padding="{TemplateBinding Margin}"Snapstodevicepixels="{TemplateBinding Snapstodevicepixels}"Cornerradius= "5"> <ContentPresenter/> </Border> </Grid> </ControlTemplate> </Setter.value> </Setter> </Style></ResourceDictionary>
3. Referencing a custom file: Open the App.xaml file and add the resource dictionary file reference in <Application.Resources></Application.Resources>
<Applicationx:class= "Wpftest.app"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local= "Clr-namespace:wpftest"StartupUri= "MainWindow.xaml"> <application.resources> <ResourceDictionary> <resourcedictionary.mergeddictionaries> <ResourceDictionarySource= "Pack://application:,,,/wpftest;component/resources/style.xaml"/> </resourcedictionary.mergeddictionaries> </ResourceDictionary> </application.resources></Application>
WPF Learning notes-Using a custom resource dictionary (style) file