码迷,mamicode.com
首页 > Windows程序 > 详细

WPF学习笔记-使用自定义资源字典(style)文件

时间:2016-12-14 14:11:10      阅读:2006      评论:0      收藏:0      [点我收藏+]

标签:val   for   device   main   wpf   stat   cat   inf   resource   

1、添加资源字典文件style.xmal

技术分享

2、在资源字典中添加自定义style等

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WpfTest.resources">
    <Style x: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>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Grid Margin="10">
                        <Rectangle Fill="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"  
                               RadiusX="5" RadiusY="5">
                            <Rectangle.Effect>
                                <DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Border Background="{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、引用自定义文件:打开App.xaml文件,在<Application.Resources></Application.Resources>中添加资源字典文件引用

<Application x: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>
                <ResourceDictionary Source="pack://application:,,,/WpfTest;component/resources/style.xaml"/>
            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
    </Application.Resources>
</Application>

 

WPF学习笔记-使用自定义资源字典(style)文件

标签:val   for   device   main   wpf   stat   cat   inf   resource   

原文地址:http://www.cnblogs.com/theroad/p/6178795.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!