WPF自定义Window窗体样式
资源文件代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- 最大化按钮形状 --> <PathGeometry x:Key="pathMaximize"> <PathGeometry.Figures> M1,1 L1 ,11 L11,11 L11,1 z M0,0 L12,0 L12,12 L0,12 z </PathGeometry.Figures> </PathGeometry> <!-- 还原按钮形状 --> <PathGeometry x:Key="pathRestore"> <PathGeometry.Figures> M1,3 L1,11 L9,11 L9,3 z M3,1 L3,2 L10,2 L10,9 L11,9 L11,1 z M2 ,0 L12,0 L12,10 L10,10 L10,12 L0,12 L0,2 L2 ,2 z </PathGeometry.Figures> </PathGeometry> <!-- 窗体模板 --> <ControlTemplate x:Key="tmplWindowEx" TargetType="{x:Type Window}"> <Border> <Border CornerRadius="5" Background="#0998B8" Margin="{Binding BorderMargin}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="28"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <TextBlock Text="{TemplateBinding Title}" Margin="10 0 0 0" FontFamily="微软雅黑,黑体" FontSize="12" Foreground="#fff" VerticalAlignment="Center"></TextBlock> <!-- Border用于遮盖Title --> <Border Margin="88 0 0 0" CornerRadius="0 5 0 0" Background="#0998B8" Width="90" HorizontalAlignment="{Binding BtnPanelHorizontalAlignment}"></Border> <StackPanel Orientation="Horizontal" HorizontalAlignment="{Binding BtnPanelHorizontalAlignment}" Margin="98 0 5 0"> <Button x:Name="btnMinimize" Width="28" Height="28" WindowChrome.IsHitTestVisibleInChrome="True" Command="{Binding DataContext.WindowBtnCommand, RelativeSource={RelativeSource AncestorType=Window}}" CommandParameter="1" Visibility="{Binding BtnMinimizeVisibility}" > <Button.Template> <ControlTemplate> <Grid x:Name="grid" Background="Transparent"> <Path x:Name="path1" Width="12" Height="12" Fill="#fff" Data="M0,5 L12,5 L12,6 L0,6 z" VerticalAlignment="Center" HorizontalAlignment="Center"></Path> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="grid" Property="Background" Value="#0988a8"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnMaximize" Width="28" Height="28" WindowChrome.IsHitTestVisibleInChrome="True" Command="{Binding DataContext.WindowBtnCommand, RelativeSource={RelativeSource AncestorType=Window}}" CommandParameter="2" Visibility="{Binding BtnMaximizeVisibility}" > <Button.Template> <ControlTemplate> <Grid x:Name="grid" Background="Transparent"> <Path x:Name="path1" Width="12" Height="12" Fill="#fff" Data="{Binding BtnMaximizePathData}" VerticalAlignment="Center" HorizontalAlignment="Center" ></Path> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="grid" Property="Background" Value="#0988a8"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnClose" Width="28" Height="28" WindowChrome.IsHitTestVisibleInChrome="True" Command="{Binding DataContext.WindowBtnCommand, RelativeSource={RelativeSource AncestorType=Window}}" CommandParameter="3"> <Button.Template> <ControlTemplate> <Grid x:Name="grid" Background="Transparent"> <Path x:Name="path1" Width="12" Height="12" Fill="#fff" Data="M1,0 L6,5 L11,0 L12,1 L7,6 L12,11 L11,12 L6,7 L1,12 L0,11 L5,6 L0,1 z" VerticalAlignment="Center" HorizontalAlignment="Center" ></Path> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="grid" Property="Background" Value="#0988a8"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> </StackPanel> <Border Background="#d6e7f1" CornerRadius="3 0 3 3" Grid.Row="1" Margin="3 0 3 3" > <ContentPresenter ></ContentPresenter> </Border> </Grid> </Border> </Border> </ControlTemplate> <!-- 窗体样式 --> <Style x:Key="stlWindowEx" TargetType="{x:Type Window}"> <Setter Property="Template" Value="{StaticResource tmplWindowEx}"/> <!--在代码中设置AllowsTransparency和WindowStyle--> <!--<Setter Property="AllowsTransparency" Value="True"></Setter>--> <!--<Setter Property="WindowStyle" Value="None" />--> <Setter Property="Background" Value="Transparent"></Setter> <Setter Property="BorderThickness" Value="0" /> <Setter Property="BorderBrush" Value="Transparent" /> <Setter Property="ResizeMode" Value="NoResize" /> <Setter Property="ShowInTaskbar" Value="False" /> <Setter Property="WindowChrome.WindowChrome"> <Setter.Value> <WindowChrome CornerRadius="5" CaptionHeight="28" GlassFrameThickness="0" UseAeroCaptionButtons="False" NonClientFrameEdges="None"> </WindowChrome> </Setter.Value> </Setter> </Style> </ResourceDictionary>
自定义窗体封装WindowEx类代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Resources; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Windows.Resources; using System.Windows.Shapes; namespace SunCreate.Common.Controls { /// <summary> /// 窗体封装 /// </summary> public class WindowEx : Window, INotifyPropertyChanged { public event EventHandler<WindowExFixEventArgs> FixEvent; private ResourceDictionary _resource; private ICommand _WindowBtnCommand; /// <summary> /// 窗体按钮命令 /// </summary> public ICommand WindowBtnCommand { get { return _WindowBtnCommand; } set { _WindowBtnCommand = value; OnPropertyChanged("WindowBtnCommand"); } } private Thickness _BorderMargin = new Thickness(0, 0, 0, 0); public Thickness BorderMargin { get { return _BorderMargin; } set { _BorderMargin = value; OnPropertyChanged("BorderMargin"); } } private HorizontalAlignment _BtnPanelHorizontalAlignment = HorizontalAlignment.Right; /// <summary> /// 窗体按钮的Panel位置 /// </summary> public HorizontalAlignment BtnPanelHorizontalAlignment { get { return _BtnPanelHorizontalAlignment; } set { _BtnPanelHorizontalAlignment = value; OnPropertyChanged("BtnPanelHorizontalAlignment"); } } private Visibility _BtnMinimizeVisibility = Visibility.Visible; /// <summary> /// 窗体最小化按钮的显示状态 /// </summary> public Visibility BtnMinimizeVisibility { get { return _BtnMinimizeVisibility; } set { _BtnMinimizeVisibility = value; OnPropertyChanged("BtnMinimizeVisibility"); } } private Visibility _BtnMaximizeVisibility = Visibility.Visible; /// <summary> /// 窗体最大化按钮的显示状态 /// </summary> public Visibility BtnMaximizeVisibility { get { return _BtnMaximizeVisibility; } set { _BtnMaximizeVisibility = value; OnPropertyChanged("BtnMaximizeVisibility"); } } private Geometry _BtnMaximizePathData; /// <summary> /// 窗体最大化按钮的样式 /// </summary> public Geometry BtnMaximizePathData { get { return _BtnMaximizePathData; } set { _BtnMaximizePathData = value; OnPropertyChanged("BtnMaximizePathData"); } } private Visibility _TitleVisibility = Visibility.Visible; /// <summary> /// 是否显示标题 /// </summary> public Visibility TitleVisibility { get { return _TitleVisibility; } set { _TitleVisibility = value; OnPropertyChanged("TitleVisibility"); } } private WindowExTheme _Theme = WindowExTheme.Default; /// <summary> /// 窗体主题 /// </summary> public WindowExTheme Theme { get { return _Theme; } set { _Theme = value; OnPropertyChanged("Theme"); } } /// <summary> /// 窗体 构造函数 /// </summary> public WindowEx() { this.Loaded += WindowEx_Loaded; this.DataContext = this; #region 窗体样式设置 //this.AllowsTransparency = true; //AllowsTransparency会导致视频播放不显示 this.WindowStyle = WindowStyle.None; #endregion #region 窗体按钮事件 WindowBtnCommand windowBtnCommand = new WindowBtnCommand(); windowBtnCommand.DoAction = (parameter) => { if (parameter == 1) //最小化 { MinimizedSet(); this.WindowState = WindowState.Minimized; } if (parameter == 2) //窗口还原、最大化 { if (this.WindowState == WindowState.Normal) { MaximizedSet(); this.WindowState = WindowState.Maximized; } else if (this.WindowState == WindowState.Maximized) { RestoredSet(); this.WindowState = WindowState.Normal; } else if (this.WindowState == WindowState.Minimized) { RestoredSet(); this.WindowState = WindowState.Normal; } } if (parameter == 3) //关闭窗口 { this.Close(); } if (parameter == 4) //固定窗口 { if (FixEvent != null) { WindowExFixEventArgs args = new WindowExFixEventArgs(this.Content); FixEvent(this, args); } } }; this.WindowBtnCommand = windowBtnCommand; this.StateChanged += (s, e) => { if (this.WindowState == WindowState.Maximized) { MaximizedSet(); } if (this.WindowState == WindowState.Normal) { RestoredSet(); } if (this.WindowState == WindowState.Minimized) { MinimizedSet(); } }; #endregion } /// <summary> /// 窗体Loaded /// </summary> private void WindowEx_Loaded(object sender, RoutedEventArgs e) { #region 窗体样式设置 Uri uri = null; switch (Theme) { case WindowExTheme.Default: uri = new Uri("/SunCreate.Common.Controls;Component/WindowEx/WindowExResource.xaml", UriKind.Relative); break; case WindowExTheme.MessageBox: uri = new Uri("/SunCreate.Common.Controls;Component/WindowEx/MessageBoxExResource.xaml", UriKind.Relative); break; case WindowExTheme.TabContainer: uri = new Uri("/SunCreate.Common.Controls;Component/WindowEx/TabContainerResource.xaml", UriKind.Relative); break; } _resource = new ResourceDictionary(); _resource.Source = uri; this.Style = _resource["stlWindowEx"] as Style; if (this.WindowState == WindowState.Maximized) { this.BtnMaximizePathData = _resource["pathRestore"] as PathGeometry; } else { this.BtnMaximizePathData = _resource["pathMaximize"] as PathGeometry; } #endregion #region 最大化设置 if (this.WindowState == WindowState.Maximized) { this.BorderMargin = CalculateWinMargin(true); } #endregion } #region 最小化设置 private void MinimizedSet() { this.BorderMargin = new Thickness(0, 0, 0, 0); BtnPanelHorizontalAlignment = HorizontalAlignment.Left; BtnMinimizeVisibility = Visibility.Collapsed; if (this.Content != null) (this.Content as FrameworkElement).Visibility = Visibility.Collapsed; //最小化时隐藏Content if (this.Theme == WindowExTheme.TabContainer) TitleVisibility = Visibility.Visible; this.BtnMaximizePathData = _resource["pathRestore"] as PathGeometry; } #endregion #region 还原设置 private void RestoredSet() { this.BorderMargin = new Thickness(0, 0, 0, 0); BtnPanelHorizontalAlignment = HorizontalAlignment.Right; BtnMinimizeVisibility = Visibility.Visible; if (this.Content != null) (this.Content as FrameworkElement).Visibility = Visibility.Visible; //最大化或还原时显示Content this.BtnMaximizePathData = _resource["pathMaximize"] as PathGeometry; if (this.Theme == WindowExTheme.TabContainer) TitleVisibility = Visibility.Collapsed; } #endregion #region 最大化设置 private void MaximizedSet() { this.BorderMargin = CalculateWinMargin(false); BtnPanelHorizontalAlignment = HorizontalAlignment.Right; BtnMinimizeVisibility = Visibility.Visible; if (this.Content != null) (this.Content as FrameworkElement).Visibility = Visibility.Visible; //最大化或还原时显示Content this.BtnMaximizePathData = _resource["pathRestore"] as PathGeometry; if (this.Theme == WindowExTheme.TabContainer) TitleVisibility = Visibility.Collapsed; } #endregion #region 计算窗体Margin大小 /// <summary> /// 计算窗体Margin大小 /// </summary> private Thickness CalculateWinMargin(bool firstLoad = false) { double taskBarHeight = SystemParameters.PrimaryScreenHeight - SystemParameters.WorkArea.Height; double taskBarWidth = SystemParameters.PrimaryScreenWidth - SystemParameters.WorkArea.Width; if (this.Theme == WindowExTheme.TabContainer || firstLoad) { if (taskBarWidth > 0) { return new Thickness(7, 7, taskBarWidth + 7, 7); } if (taskBarHeight > 0) { return new Thickness(7, 7, 7, taskBarHeight + 7); } return new Thickness(7, 7, 7, 7); } else { if (taskBarWidth > 0) { return new Thickness(0, 0, taskBarWidth, 0); } if (taskBarHeight > 0) { return new Thickness(0, 0, 0, taskBarHeight); } return new Thickness(0, 0, 0, 0); } } #endregion #region 实现INotifyPropertyChanged接口 public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(name)); } } #endregion } }
窗体最小化、最大化、关闭按钮的命令WindowBtnCommand:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace SunCreate.Common.Controls { public class WindowBtnCommand : ICommand { public Action<int> DoAction { get; set; } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public bool CanExecute(object parameter) { return true; } public void Execute(object parameter) { if (DoAction != null) { DoAction(Convert.ToInt32(parameter)); } } } }
使用WindowEx类的示例代码:
<ui:WindowEx x:Class="SunCreate.Common.Controls.Demo.MyWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="clr-namespace:SunCreate.Common.Controls;assembly=SunCreate.Common.Controls" Title="视频播放视频播放ABCDEFG" Height="300" Width="500" WindowStartupLocation="CenterScreen" BtnMinimizeVisibility="Visible" BtnMaximizeVisibility="Visible" > <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/SunCreate.Common.Controls;Component/Themes/ScrollViewer.xaml"/> <ResourceDictionary Source="/SunCreate.Common.Controls;Component/Themes/ControlsResource.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <StackPanel> <Border Margin="10"> <Button Height="30" Width="80" Content="测试" Style="{StaticResource stlTxtBtn}" HorizontalAlignment="Left" Click="Button_Click" /> </Border> <Border Margin="10"> <TextBlock Text="测试内容ABC"></TextBlock> </Border> </StackPanel> </Grid> </ui:WindowEx>
效果图:
窗体最小化效果图:
补充:
ScrollViewer.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="IsTabStop" Value="false" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Thumb}"> <Grid> <Rectangle Fill="#90000000" RadiusX="3" RadiusY="3" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="HorizontalScrollBarPageButton" TargetType="{x:Type RepeatButton}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="Focusable" Value="false" /> <Setter Property="IsTabStop" Value="false" /> <Setter Property="Opacity" Value="0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <Rectangle Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="VerticalScrollBarPageButton" TargetType="{x:Type RepeatButton}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="Focusable" Value="false" /> <Setter Property="IsTabStop" Value="false" /> <Setter Property="Opacity" Value="0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <Rectangle Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="for_scrollbar" TargetType="{x:Type ScrollBar}"> <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" /> <Setter Property="Stylus.IsFlicksEnabled" Value="false" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="Margin" Value="0,1,1,6" /> <Setter Property="Width" Value="7" /> <Setter Property="MinWidth" Value="7" /> <Setter Property="Opacity" Value="0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollBar}"> <Grid x:Name="Bg" SnapsToDevicePixels="true"> <Track x:Name="PART_Track" IsEnabled="{TemplateBinding IsMouseOver}" IsDirectionReversed="true"> <Track.DecreaseRepeatButton> <RepeatButton Style="{StaticResource VerticalScrollBarPageButton}" Command="{x:Static ScrollBar.PageUpCommand}" /> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Style="{StaticResource VerticalScrollBarPageButton}" Command="{x:Static ScrollBar.PageDownCommand}" /> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb Style="{StaticResource ScrollBarThumb}" /> </Track.Thumb> </Track> </Grid> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Orientation" Value="Horizontal"> <Setter Property="Background" Value="Transparent" /> <Setter Property="Margin" Value="1,0,6,1" /> <Setter Property="Height" Value="5" /> <Setter Property="MinHeight" Value="5" /> <Setter Property="Width" Value="Auto" /> <Setter Property="Opacity" Value="0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollBar}"> <Grid x:Name="Bg" SnapsToDevicePixels="true"> <Track x:Name="PART_Track" IsEnabled="{TemplateBinding IsMouseOver}"> <Track.DecreaseRepeatButton> <RepeatButton Style="{StaticResource HorizontalScrollBarPageButton}" Command="{x:Static ScrollBar.PageLeftCommand}" /> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Style="{StaticResource HorizontalScrollBarPageButton}" Command="{x:Static ScrollBar.PageRightCommand}" /> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb Style="{StaticResource ScrollBarThumb}" /> </Track.Thumb> </Track> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> <!-- ScrollViewer --> <Style TargetType="{x:Type ScrollViewer}"> <Setter Property="BorderBrush" Value="LightGray" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="VerticalContentAlignment" Value="Top" /> <Setter Property="VerticalScrollBarVisibility" Value="Auto" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Grid Background="{TemplateBinding Background}"> <ScrollContentPresenter Cursor="{TemplateBinding Cursor}" Margin="{TemplateBinding Padding}" ContentTemplate="{TemplateBinding ContentTemplate}" CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}" /> <ScrollBar x:Name="PART_VerticalScrollBar" HorizontalAlignment="Right" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Style="{StaticResource for_scrollbar}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" /> <ScrollBar x:Name="PART_HorizontalScrollBar" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Style="{StaticResource for_scrollbar}" VerticalAlignment="Bottom" Value="{TemplateBinding HorizontalOffset}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" /> </Grid> </Border> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="ScrollChanged"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" BeginTime="0:0:1" /> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" BeginTime="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseEnter" SourceName="PART_VerticalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave" SourceName="PART_VerticalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseEnter" SourceName="PART_HorizontalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave" SourceName="PART_HorizontalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}"> <Setter Property="BorderBrush" Value="LightGray" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="HorizontalScrollBarVisibility" Value="Auto" /> <Setter Property="VerticalContentAlignment" Value="Top" /> <Setter Property="VerticalScrollBarVisibility" Value="Auto" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Grid Background="{TemplateBinding Background}"> <Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition Height="1*" /> </Grid.RowDefinitions> <GridViewHeaderRowPresenter Margin="2,0,2,0" Columns="{Binding Path=TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> <ScrollContentPresenter Grid.Row="1" Cursor="{TemplateBinding Cursor}" Margin="{TemplateBinding Padding}" ContentTemplate="{TemplateBinding ContentTemplate}" /> <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Row="1" HorizontalAlignment="Right" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Style="{StaticResource for_scrollbar}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" /> <ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Row="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Style="{StaticResource for_scrollbar}" VerticalAlignment="Bottom" Value="{TemplateBinding HorizontalOffset}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" /> </Grid> </Border> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="ScrollChanged"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" BeginTime="0:0:1" /> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" BeginTime="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseEnter" SourceName="PART_VerticalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave" SourceName="PART_VerticalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseEnter" SourceName="PART_HorizontalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave" SourceName="PART_HorizontalScrollBar"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="PART_HorizontalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
ControlsResource.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> </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>