1.首先声明静态资源
1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:sys="clr-namespace:System;assembly=mscorlib" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 4 //<SolidColorBrush> 5 <SolidColorBrush x:Key="***" Color="#001122"></SolidColorBrush> 6 <SolidColorBrush x:Key="***" Color="White"></SolidColorBrush> 7 <SolidColorBrush x:Key="***" Color="Transparent"></SolidColorBrush> 8 9 //<DropShadowEffect> 10 <DropShadowEffect x:Key="***" Color="#001122" BlurRadius="8" ShadowDeph="0" Direction="0" Opacity="0.7"> 11 </DropShadowEffect> 12 13 //<LinearGradientBrush> 14 <LinearGradientBrush x:Key="***" StartPoint="0.5,0" EndPoint="0.5,1"> 15 <GradientStop Color="#001122" Offset="0"> 16 <GradientStop Color="#112233" Offset="1"> 17 </LinearGradientBrush> 18 19 //<FontFamily> 20 <FontFamily x:Key="***">Microsoft Yahei</FontFamily> 21 </ResourceDictionary>
2.声明样式
1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:local="clr-namespace:Util.Controls" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 4 //TextBlock 5 <Style TargetType="{x:Type TextBlock}"> 6 <Setter Property="Foreground" Value="{StaticResource TextForeGround}"/> 7 <Setter Property="FontFamily" Value="{StaticResource FontFamily}"/> 8 <Setter Property="FontSize" Value="{StaticResource FontSize}"/> 9 </Style> 10 11 //ToolTip 12 <Style Target="{x:Type ToolTip}"> 13 <Setter Property="Foreground" Value="{StaticResource TextForeground}"/> 14 <Setter Property="FontFamily" Value="{StaticResource FontFamily}"/> 15 <Setter Property="FontSize" Value="{StaticResource FontSize}"/> 16 <Setter Property="Background" Value="{StaticResource HeaderBackground}"/> 17 <Setter Property="BorderBrush" Value="{StaticResource FocusBorderBrush}"/> 18 <Setter Property="BorderThickness" Value="1"/> 19 <Setter Property="Template"> 20 <Setter.Value> 21 <ControlTemplate TargetType="{x:Type ToolTip}"> 22 <Border CornerRadius="2" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"> 23 <ContentPresenter Margin="8,5,8,5"/> 24 </Border> 25 </ControlTemplate> 26 </Setter.Value> 27 </Setter> 28 </Style> 29 </ResourceDictionary>
3.声明样式
1 <ResourceDictionary> 2 <ResourceDictionary.MergeDictionaries> 3 //... 4 <ResourceDictionary Source="pack://application:,,,WpfApplication.Controls;component/Style/Global.xaml"> 5 // 资源问价在当前程序集 当前的命名空间 本地路径:Style/Global.xaml 6 //... 7 </ResourceDictionary.MergeDictionaries> 8 </ResourceDictionary>
时间: 2024-10-01 15:43:21