WPF Learning notes-Using a custom resource dictionary (style) file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.