常用控件样式:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- 文字按钮 --> <Style x:Key="stlTxtBtn" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="Transparent"> <Border x:Name="bd" Background="#1aa4f5" CornerRadius="2" Padding="{TemplateBinding Padding}"> <TextBlock x:Name="txt" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2 5 2" Foreground="White" ><InlineUIContainer> <ContentPresenter /> </InlineUIContainer></TextBlock> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="bd" Property="Background" Value="#33c4f5"/> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="txt" Property="FontSize" Value="11"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 文字按钮浅色 --> <Style x:Key="stlTxtBtnLight" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Background="Transparent"> <Border x:Name="bd" Background="#0cc663" CornerRadius="2" Padding="{TemplateBinding Padding}"> <TextBlock x:Name="txt" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2 5 2" Foreground="White" ><InlineUIContainer> <ContentPresenter /> </InlineUIContainer></TextBlock> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="bd" Property="Background" Value="#0cb653"/> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="txt" Property="FontSize" Value="11"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 图片按钮 --> <ControlTemplate x:Key="tmplImgBtn" TargetType="{x:Type Button}"> <Border x:Name="bd" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" CornerRadius="2" Background="{TemplateBinding Background}" > <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <Image x:Name="img" Margin="-2 2 3 0" Width="15" Height="15" VerticalAlignment="Center" Stretch="UniformToFill" Source="{TemplateBinding Tag}" /> <TextBlock x:Name="txt" FontSize="{TemplateBinding Property=FontSize}" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Property=Content}" VerticalAlignment="Center"/> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="bd" Property="Background" Value="#33c4f5"/> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="txt" Property="FontSize" Value="11"/> <Setter TargetName="img" Property="Width" Value="14"/> <Setter TargetName="img" Property="Height" Value="14"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- 图片按钮 --> <Style x:Key="stlImgBtn" TargetType="{x:Type Button}"> <Setter Property="Margin" Value="5,0"/> <Setter Property="Height" Value="25"/> <Setter Property="Foreground" Value="White"/> <Setter Property="Background" Value="#15A6F9"/> <Setter Property="Template" Value="{StaticResource tmplImgBtn}"/> </Style> <!-- 只有图片的按钮 --> <ControlTemplate x:Key="tmplBtnImgOnly" TargetType="{x:Type Button}"> <Border Background="#aa013440" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" > <Image x:Name="img" Width="16" Height="16" Stretch="Fill" Source="{TemplateBinding Property=Content}"></Image> </Border> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="img" Property="Margin" Value="2"></Setter> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter TargetName="img" Property="Opacity" Value="0.5"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- 输入框样式 --> <Style TargetType="{x:Type TextBox}" x:Key="stlTxt"> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Height" Value="28"/> <Setter Property="Margin" Value="5,0,0,0"/> <Setter Property="Foreground" Value="White"/> <Setter Property="CaretBrush" Value="White"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Border CornerRadius="2" BorderThickness="0" BorderBrush="#eee" Background="#0A5D7B"> <Grid> <Border x:Name="BorderBase" Background="Transparent" BorderThickness="1.4,1.4,1,1" BorderBrush="Transparent" /> <Label x:Name="TextPrompt" Content="{TemplateBinding Tag}" Foreground="Gray" VerticalAlignment="Center" Visibility="Collapsed" Focusable="False" /> <ScrollViewer Margin="2 0 0 0" VerticalAlignment="Center" x:Name="PART_ContentHost" /> </Grid> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsFocused" Value="False"/> <Condition Property="Text" Value=""/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="TextPrompt" Value="Visible"/> </MultiTrigger> <Trigger Property="IsFocused" Value="True"> <Setter Property="BorderThickness" TargetName="BorderBase" Value="2.4,1.4,1,1"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="Gray" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 输入框样式 --> <Style TargetType="{x:Type RichTextBox}" x:Key="stlRtb"> <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Margin" Value="5 0 0 0"/> <Setter Property="Foreground" Value="White"/> <Setter Property="CaretBrush" Value="White"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RichTextBox}"> <Border BorderThickness="0" BorderBrush="#eee" CornerRadius="2" Background="#0A5D7B"> <Grid> <Border x:Name="BorderBase" Background="Transparent" BorderThickness="1.4,1.4,1,1" BorderBrush="Transparent" /> <Label x:Name="TextPrompt" Content="{TemplateBinding Tag}" Foreground="Gray" VerticalAlignment="Top" Visibility="Collapsed" Focusable="False" /> <Border x:Name="border" Margin="0 8 0 5"> <ScrollViewer Margin="0" VerticalAlignment="Top" x:Name="PART_ContentHost" Height="{Binding ActualHeight, ElementName=border}" /> </Border> </Grid> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsFocused" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="TextPrompt" Value="Visible"/> </MultiTrigger> <Trigger Property="IsFocused" Value="True"> <Setter Property="BorderThickness" TargetName="BorderBase" Value="2.4,1.4,1,1"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="Gray" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--下拉条目样式--> <Style TargetType="{x:Type ComboBoxItem}" x:Key="stlCbxItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Height" Value="28" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBoxItem}"> <Grid Background="{TemplateBinding Background}" Margin="0,0.5"> <Border x:Name="ItemBackground" CornerRadius="1" IsHitTestVisible="False" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" /> <ContentPresenter x:Name="contentPresenter" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="ItemBackground" Property="Background" Value="#224466" /> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="ItemBackground" Property="Background" Value="#226688" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 下拉框样式 --> <Style TargetType="{x:Type ToggleButton}" x:Key="stlToggleButton"> <Setter Property="Foreground" Value="White"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid Background="Transparent"> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.7*"/> <ColumnDefinition Width="0.3*" MaxWidth="30" MinWidth="16"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Foreground="White" Margin="5 0 0 0" Text="{Binding Text, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}, Mode=FindAncestor}}" VerticalAlignment="Center"/> <Border Grid.Column="1" x:Name="Back" Background="Transparent" BorderThickness="0" BorderBrush="Transparent"> <Path x:Name="PathFill" Fill="#1b94e0" Width="8" Height="6" StrokeThickness="0" Data="M5,0 L10,10 L0,10 z" RenderTransformOrigin="0.5,0.5" Stretch="Fill"> <Path.RenderTransform> <TransformGroup> <ScaleTransform /> <SkewTransform /> <RotateTransform Angle="180"/> <TranslateTransform/> </TransformGroup> </Path.RenderTransform> </Path> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="PathFill" Property="Fill" Value="#1b94e0"/> <Setter TargetName="Back" Property="Background" Value="Transparent"/> <Setter TargetName="Back" Property="BorderBrush" Value="Transparent"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 下拉框样式 --> <Style x:Key="stlCbx" TargetType="{x:Type ComboBox}" > <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.CanContentScroll" Value="True"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Height" Value="28"/> <Setter Property="Margin" Value="0,0,0,0"/> <Setter Property="ItemContainerStyle" Value="{StaticResource stlCbxItem}" /> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{Binding Text}" Foreground="#fff" Margin="0 3 0 3" /> </DataTemplate> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBox}"> <Border BorderThickness="0" BorderBrush="#eee" CornerRadius="2" Background="#0A5D7B"> <Grid> <ToggleButton Style="{StaticResource stlToggleButton}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/> <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide" > <Border MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True" Background="Transparent" > <Border Background="#002244" CornerRadius="2" Margin="0 2 0 0"> <ScrollViewer Margin="4,6,4,6" Style="{DynamicResource ScrollViewerStyle}" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> <!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True --> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="#002244" /> </ScrollViewer> </Border> </Border> </Popup> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 复选框样式 --> <ControlTemplate x:Key="tmplCkb" TargetType="{x:Type CheckBox}"> <Grid x:Name="buttonContent" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"> <Image x:Name="btnImageSrc" Stretch="Fill" Source="/SunCreate.Common.Controls;Component/Images/Controls/复选1.png"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="btnImageSrc" Property="Source" Value="/SunCreate.Common.Controls;Component/Images/Controls/复选2.png"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- 单选按钮样式(带背景色) --> <ControlTemplate x:Key="tmplRdbBackground" TargetType="{x:Type RadioButton}"> <Grid> <Border x:Name="bd2" CornerRadius="2" Opacity="1" BorderThickness="1" BorderBrush="{TemplateBinding Background}" SnapsToDevicePixels="True"/> <Border x:Name="bd" CornerRadius="2" Opacity="0" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"/> <Border x:Name="backgroundRadioBoard" Height="{TemplateBinding Property=Height}" Width="{TemplateBinding Property=Width}" Background="Transparent"> <TextBlock FontSize="{TemplateBinding Property=FontSize}" Text="{TemplateBinding Property=Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Property=Foreground}"/> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="bd" Property="Opacity" Value="1"/> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="bd" Property="Opacity" Value="1"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- 单选按钮样式(带小圆圈) --> <ControlTemplate x:Key="tmplRdbCircle" TargetType="{x:Type RadioButton}"> <Border x:Name="radioBtnBoard" CornerRadius="2" Height="{TemplateBinding Property=Height}" Width="{TemplateBinding Property=Width}" Background="Transparent"> <StackPanel Orientation="Horizontal"> <Image x:Name="img" Margin="5 0 5 0" Width="14" Height="14" Stretch="Fill" Source="/SunCreate.Common.Controls;Component/Images/Controls/单选1.png"/> <TextBlock x:Name="txt" Margin="0 0 5 0" FontSize="{TemplateBinding Property=FontSize}" Text="{TemplateBinding Property=Content}" VerticalAlignment="Center" Foreground="{TemplateBinding Property=Foreground}" /> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="img" Property="Source" Value="/SunCreate.Common.Controls;Component/Images/Controls/单选2.png"/> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="radioBtnBoard" Property="Background" Value="#331aa4f5"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- 单选按钮样式 --> <ControlTemplate x:Key="tmplRdb" TargetType="{x:Type RadioButton}"> <Border x:Name="radioBtnBoard" CornerRadius="2" Height="{TemplateBinding Property=Height}" Width="{TemplateBinding Property=Width}" Background="Transparent"> <TextBlock x:Name="txt" FontSize="{TemplateBinding Property=FontSize}" Text="{TemplateBinding Property=Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Property=Foreground}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="radioBtnBoard" Property="Background" Value="#1aa4f5"/> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="radioBtnBoard" Property="Background" Value="#331aa4f5"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- 单选按钮样式 --> <Style x:Key="stlRdb" TargetType="{x:Type RadioButton}"> <Setter Property="FontSize" Value="11"/> <Setter Property="Height" Value="22"/> <Setter Property="Width" Value="50"/> <Setter Property="Foreground" Value="White"/> <Setter Property="Margin" Value="5,0"/> <Setter Property="Template" Value="{StaticResource tmplRdb}"/> </Style> <!-- 单选按钮样式(带小圆圈) --> <Style x:Key="stlRdbCircle" TargetType="{x:Type RadioButton}"> <Setter Property="FontSize" Value="11"/> <Setter Property="Height" Value="22"/> <Setter Property="Foreground" Value="White"/> <Setter Property="Margin" Value="5,0"/> <Setter Property="Template" Value="{StaticResource tmplRdbCircle}"/> </Style> <!-- 单选按钮样式(带背景色) --> <Style x:Key="stlRdbBackground" TargetType="{x:Type RadioButton}"> <Setter Property="FontSize" Value="11"/> <Setter Property="Height" Value="22"/> <Setter Property="Width" Value="50"/> <Setter Property="Foreground" Value="White"/> <Setter Property="Margin" Value="5,0"/> <Setter Property="Template" Value="{StaticResource tmplRdbBackground}"/> </Style> <!--Slider样式--> <Style x:Key="stlRepeatButtonLeft" TargetType="RepeatButton"> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RepeatButton"> <Border Background="#01ffff" SnapsToDevicePixels="True" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="stlRepeatButtonRight" TargetType="RepeatButton"> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RepeatButton"> <Border Background="#0998B8" SnapsToDevicePixels="True" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="stlThumb" TargetType="Thumb"> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Thumb"> <Grid> <Border Margin="0 -4 0 -4" Background="#01ffff" Width="8" Height="12" SnapsToDevicePixels="True"> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="stlThumbReadOnly" TargetType="Thumb"> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Thumb"> <Grid> <Border Margin="0 0 0 0" Background="#01ffff" Width="0" Height="4"> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="stlSlider" TargetType="Slider"> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Slider"> <Grid> <Border Height="4"> <Track Name="PART_Track"> <Track.DecreaseRepeatButton> <RepeatButton Style="{StaticResource stlRepeatButtonLeft}" Command="Slider.DecreaseLarge"/> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Style="{StaticResource stlRepeatButtonRight}" Command="Slider.IncreaseLarge"/> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb Style="{StaticResource stlThumb}"/> </Track.Thumb> </Track> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="stlSliderReadOnly" TargetType="Slider"> <Setter Property="IsEnabled" Value="false" /> <Setter Property="Focusable" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Slider"> <Grid> <Border Height="4"> <Track Name="PART_Track"> <Track.DecreaseRepeatButton> <RepeatButton Style="{StaticResource stlRepeatButtonLeft}" Command="Slider.DecreaseLarge"/> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Style="{StaticResource stlRepeatButtonRight}" Command="Slider.IncreaseLarge"/> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb Style="{StaticResource stlThumbReadOnly}"/> </Track.Thumb> </Track> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--ToolTip样式--> <Style x:Key="stlToolTip" TargetType="ToolTip"> <Setter Property ="Background" Value="#99001133"></Setter> <Setter Property ="BorderThickness" Value="0"></Setter> <Setter Property ="ContentTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{TemplateBinding Content}" Foreground="#fff" Background="Transparent" TextWrapping="Wrap"></TextBlock> </DataTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>