WPF学习笔记-使用自定义资源字典(style)文件
2016-12-14 12:24
369 查看
1、添加资源字典文件style.xmal
2、在资源字典中添加自定义style等
3、引用自定义文件:打开App.xaml文件,在<Application.Resources></Application.Resources>中添加资源字典文件引用
4、将样式应用到窗口的布局上,边框阴影窗体
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="resources/style.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
4、将样式应用到窗口的布局上,边框阴影窗体
<Window x:Class="WpfTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfTest" mc:Ignorable="d" Title="Window1" Style="{StaticResource for_noresize_window}"> <Grid> </Grid> </Window>
相关文章推荐
- WPF学习笔记--使用配置文件修改控件、面板颜色
- WPF中使用WinForm控件预览DWG文件(学习笔记)
- WPF and Silverlight 学习笔记(二十七):基本图形的使用(2)Path和位图操作
- WPF学习笔记(2):在Style中设置ToolTip的问题.
- ORACLE DBA学习笔记--日志文件(使用LogMiner分析日志)
- WPF and Silverlight 学习笔记(二十五):使用CollectionView实现对绑定数据的排序、筛选、分组
- C#学习笔记(二十一):使用文件基础
- WPF and Silverlight 学习笔记(十八):WPF样式(Style)与模板(Template)
- WPF学习笔记(4):避免让WPF资源字典变得杂乱臃肿
- MonoRail学习笔记二十:资源文件的使用和多语言支持
- WPF and Silverlight 学习笔记(二十八):基本图形的使用(3)图形的操作
- JSP学习笔记(二)-----使用Tomcat运行JSP文件
- MYSQL学习笔记(5)配置:使用选项文件
- WPF学习笔记(5):合并资源字典
- C#学习笔记(十六):使用打开保存文件对话框
- C#学习笔记:使用文件基础
- C#学习笔记(二十一):使用文件基础
- C#学习笔记(十六):使用打开保存文件对话框
- WPF and Silverlight 学习笔记(二十六):基本图形使用(1)
- WPF and Silverlight 学习笔记(二十二):使用代码实现绑定、绑定数据的验证