1.先定义画刷,一般存为资源字典

格式:

  <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:sys="clr-namespace:System;assembly=mscorlib"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <!--定义 画刷-->
   <!-- 字体-->
   <!-- 等 -->
  </ResourceDictionary>

定义SolidBrush:

 <SolidColorBrush x:Key="WindowBackground" Color="#007ACB" />
 <SolidColorBrush x:Key="WindowBorderBrush" Color="Transparent" />
 <SolidColorBrush x:key="WindowForeground" Color="White" />

定义LinearGradientBrush:

 <LinearGradientBrush x:Key="CaptionBackground" StartPoint="0.5,0" EndPoint="0.5,1">
 <GradientStop Color="#571457" Offset="0"/>
 <GradientStop Color="#6A196A" Offset="1"/>
 </LinearGradientBrush>

设置边框效果:

 1<DropShadowEffect x:Key="DefaultDropShadow" Color="Black" 
BlurRadius="5" ShadowDeph="2" Direction="31" Opacity="0.6"/>

定义字体:

 <FontFamily x:Key="FontFamily">Microsoft YaHei</FontFamily>

定义数值和字符串:

  <sys:Double x:Key="FontSize">13</sys:Double>
  <sys:Double x:Key="WatermarkOpacity">0.4</sys:Double>
  <sys:String x:Key="DateFormat">yyyy年MM月dd日</sys:String>
  <sys:String x:Key="DateTimeFormat">yyyy/MM/dd HH:mm:ss</sys:String>

2.定义样式:

格式:注意需要引用当前类库的命名空间

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:local="clr-namespace:SLT.Controls"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <!---->
  <!--样式-->
  <!---->
 </ResourceDictionary>

TargetType指定样式的应用对象

 <Style TargetType="{x:Type TextBlock}">
 <Setter Property="Foreground" Value="{StaticResource TextForeground}"/>
 <Setter Property="FontFamily" Value="{StaticResource FontFamily}"/>
 <Setter Property="FontSize" Value="{StaticResource FontSize}"/>
 </Style>

带ControlTemplate的样式:

 <Style TargetType="{x:Type ToolTip}">
 <Setter Property="Foreground" Value="{StaticResource TextForeground}"/>
 <Setter Property="FontFamily" Value="{StaticResource FontFamily}"/>
 <Setter Property="FontSize" Value="{StaticResource FontSize}"/>
 <Setter Property="Background" Value="{StaticResource HeaderBackground}"/>
 <Setter Property="BorderBrush" Value="{StaticResource FocusBorderBrush}"/>
 <Setter Property="BorderThickness" Value="1"/>
 <Setter Property="Template">
 <Setter.Value>
   <ControlTemplate TargetType="{x:Type ToolTip}">
      <Border CornerRadius="2" BorderThickness="{TemplateBinding BorderThickness}" 
BorderBrush="{TemplateBinding BorderBrush}"     Background="{TemplateBinding Background}">       <ContentPresenter Margin="8,5,8,5"/>   </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>

 3.添加MergedDictionaries:

所有的样式文件需要添加说明,格式如下:

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <ResourceDictionary.MergedDictionaries>
         <!---->
         <!--此处添加样式文件-->
         <!---->
     </ResourceDictionary.MergedDictionaries>
 </ResourceDictionary>

样式文件说明需要说清文件的具体位置,如下:

1  <ResourceDictionary Source="pack://application:,,,/SLT.Controls;component/Control/HighTextBlock.xaml" />

最新文章

  1. HTTP协议下保证密码不被获取更健壮方式
  2. 爱与恨的抉择:ASP.NET 5+EntityFramework 7
  3. maven项目管理构建
  4. BizTalk开发系列(十六) XML命名空间
  5. 以普通用户登录 su root 用vncviewer:xxxxx 会报错!!exit 回到最初环境变的用户 问题解决!!!!
  6. PHP soap Web Service 使用SoapDiscovery.class.php 生成wsdl文件
  7. 前端复习-02-ajax原生以及jq和跨域方面的应用。
  8. oracle 修改表的sql语句
  9. 多线程模式之MasterWorker模式
  10. 转:【Java并发编程】之九:死锁(含代码)
  11. ORALCE删除临时表空间的方法---解决ORA01033: oralce initialization or shutdown in progress方案
  12. 那什么时候会触发BFC呢?块级格式化上下文
  13. 使用tablayout和recyclerview的时候,报重复添加Fragment错误
  14. work2:贪吃蛇
  15. linux ubuntu 关于vim得一些基本命令
  16. C#基础知识之List和数组之间的转换
  17. java并发之线程间通信
  18. Scala之隐式转换implicit详解
  19. 数组新增,修改json数据
  20. python中的BaseManager通信(二)文件二分

热门文章

  1. 使用AccessibilityService执行开机自启动
  2. volatile修饰符
  3. eclipse 中过滤空包,目录树中不显示。
  4. NSRunLoop的进一步理解
  5. javadoc
  6. django用户认证
  7. add user and grant privileges on mariadb
  8. ionic ios iframe 白屏
  9. keylogger
  10. TomCat的安装与配置方法