常用控制項樣式: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> ...
常用控制項樣式:
<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