先上张效果图, 如题所示:窗口 和 滚动的美化
本人WPF新手,高手请见笑.
窗口的美化很简单,就是从 Window 继承下来而以.整个窗口的XAML也非常简单 : 标题栏 和 内容区域. 标题栏又分为 Icon 列,标题列,系统按钮列.
窗口的 拖动/改变大小 是通过 WindowChrome 完成的, 完全没有写一句代码(.NET 4.5 内置了 WindowChrome , 4.5已下的版本需要加载另外一个DLL)
关于 WindowChrome 可以参见:
http://msdn.microsoft.com/zh-cn/library/system.windows.shell.windowchrome(v=vs.110).aspx
美化过程中遇到两个问题,一度迫使我放弃美化.
1, 最大化窗口后,窗口遮挡了任务栏.
2, 如上图所示,底部的消息和异常显示区域最小化后,无法在还原.
第一个问题, 完全参见:
http://msdn.microsoft.com/zh-cn/dd366102.aspx
或
http://www.cnblogs.com/zhouyinhui/archive/2013/02/07/1326188.html
第二个问题,在你们看来,也许不是事, 因为我用了 AvalonDock.
我试了很多方法. 只要 AllowsTransparency 为 True , 这个问题铁定是无法避免的. 不能为True , 就不能圆角化, 我将标题栏的背景色设为透明,大家看一下是什么样的:
黑乎乎的,而且还有边框.
WindowChrome 有个 CaptionHeight 属性, 它是窗口顶部标题区域的高度. 也就是在这个高度范围内, 你双击/右键都等同于在标题栏上的操作.
另外,在这个区域内的所有东西都地法响应鼠标的操作: 按钮不能点,文本框无法获取焦点等.
这显然不能满足我们需求,要不然关闭/最大化/最小化怎么响应? 这就需要使用 WndowChrome.IsHitTestVisibleInChrome 了.
1 <Button Margin="0" Name="MiniButton" Width="34" Template="{StaticResource MiniButton}" WindowChrome.IsHitTestVisibleInChrome="True" Command="{x:Static SystemCommands.MinimizeWindowCommand}" />
上面是自定义窗口的全部需要注意的地方.
附上代码:
1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 3 xmlns:local="clr-namespace:AsNum.WPF.Controls" 4 > 5 6 <SolidColorBrush Color="#FF10a8ab" x:Key="StyleWindow.TitleBackground" /> 7 8 <ControlTemplate x:Key="MiniButton" TargetType="Button"> 9 <!--一定要初始化Grid的Background属性--> 10 <Grid x:Name="MB" Background="Transparent"> 11 <Path Data="F1M0,6L0,9 9,9 9,6 0,6z" 12 SnapsToDevicePixels="True" 13 Fill="White" 14 HorizontalAlignment="Center" VerticalAlignment="Center" /> 15 </Grid> 16 <ControlTemplate.Triggers> 17 <Trigger Property="IsMouseOver" Value="True"> 18 <Setter Property="Background" TargetName="MB" Value="#99333333"/> 19 </Trigger> 20 <Trigger Property="IsPressed" Value="True"> 21 <Setter Property="Background" TargetName="MB" Value="#FF333333"/> 22 </Trigger> 23 </ControlTemplate.Triggers> 24 </ControlTemplate> 25 26 <Style x:Key="WinMaxButton" TargetType="Button"> 27 <Setter Property="Template"> 28 <Setter.Value> 29 <ControlTemplate TargetType="Button"> 30 <Grid x:Name="MB" Background="Transparent"> 31 <Path SnapsToDevicePixels="True" 32 Data="F1M0,10L0,3 3,3 3,0 10,0 10,2 4,2 4,3 7,3 7,6 6,6 6,5 1,5 1,10z M1,10L7,10 7,7 10,7 10,2 9,2 9,6 6,6 6,9 1,9z" 33 Fill="White" 34 HorizontalAlignment="Center" VerticalAlignment="Center" /> 35 </Grid> 36 <ControlTemplate.Triggers> 37 <Trigger Property="IsMouseOver" Value="True"> 38 <Setter Property="Background" TargetName="MB" Value="#99333333"/> 39 </Trigger> 40 <Trigger Property="IsPressed" Value="True"> 41 <Setter Property="Background" TargetName="MB" Value="#FF333333"/> 42 </Trigger> 43 </ControlTemplate.Triggers> 44 </ControlTemplate> 45 </Setter.Value> 46 </Setter> 47 </Style> 48 49 <Style x:Key="WinNormalButton" TargetType="Button"> 50 <Setter Property="Template"> 51 <Setter.Value> 52 <ControlTemplate TargetType="Button"> 53 <Grid x:Name="MB" Background="Transparent"> 54 <Path SnapsToDevicePixels="True" 55 Data="F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z" 56 Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" /> 57 </Grid> 58 <ControlTemplate.Triggers> 59 <Trigger Property="IsMouseOver" Value="True"> 60 <Setter Property="Background" TargetName="MB" Value="#99333333"/> 61 </Trigger> 62 <Trigger Property="IsPressed" Value="True"> 63 <Setter Property="Background" TargetName="MB" Value="#FF333333"/> 64 </Trigger> 65 </ControlTemplate.Triggers> 66 </ControlTemplate> 67 </Setter.Value> 68 </Setter> 69 </Style> 70 71 <Style x:Key="CloseButton" TargetType="Button"> 72 <Setter Property="Template"> 73 <Setter.Value> 74 <ControlTemplate TargetType="Button"> 75 <Grid x:Name="MB"> 76 <Path Data="F1M0,0L2,0 5,3 8,0 10,0 6,4 10,8 8,8 5,5 2,8 0,8 4,4 0,0z" 77 Fill="White" SnapsToDevicePixels="True" HorizontalAlignment="Center" VerticalAlignment="Center"/> 78 </Grid> 79 <ControlTemplate.Triggers> 80 <Trigger Property="IsMouseOver" Value="True"> 81 <Setter Property="Background" TargetName="MB" Value="#99333333"/> 82 </Trigger> 83 <Trigger Property="IsPressed" Value="True"> 84 <Setter Property="Background" TargetName="MB" Value="#FF333333"/> 85 </Trigger> 86 </ControlTemplate.Triggers> 87 </ControlTemplate> 88 </Setter.Value> 89 </Setter> 90 </Style> 91 92 93 94 <Style TargetType="{x:Type local:StyleWindow}"> 95 <Setter Property="AllowsTransparency" Value="False" /> 96 <!--当为True的时候,AvalonDock的LayoutAnchorablePane 最小后不能在被打开--> 97 <Setter Property="Background" Value="{x:Null}" /> 98 <Setter Property="WindowStyle" Value="None" /> 99 <Setter Property="WindowChrome.WindowChrome"> 100 <Setter.Value> 101 <WindowChrome ResizeBorderThickness="5" 102 CaptionHeight="30" 103 GlassFrameThickness="3" 104 /> 105 </Setter.Value> 106 </Setter> 107 108 <Setter Property="Template"> 109 <Setter.Value> 110 <ControlTemplate TargetType="{x:Type local:StyleWindow}"> 111 <Border Background="{TemplateBinding Background}" 112 BorderBrush="#66333333" 113 BorderThickness="1" 114 > 115 116 <Grid> 117 <Grid.RowDefinitions> 118 <RowDefinition Height="auto" Name="ROW0" /> 119 <RowDefinition /> 120 <RowDefinition Height="auto" /> 121 </Grid.RowDefinitions> 122 123 124 125 <Border Height="30" Grid.Row="0" Background="{StaticResource StyleWindow.TitleBackground}"> 126 <Grid> 127 <Grid.ColumnDefinitions> 128 <ColumnDefinition Name="COLICON" Width="auto" /> 129 <ColumnDefinition Name="COLTITLE" /> 130 <ColumnDefinition Name="COLBTNS" Width="auto" /> 131 </Grid.ColumnDefinitions> 132 <Border Grid.Column="0" Margin="3"> 133 <Image Source="{TemplateBinding Icon}" Grid.Column="0" /> 134 </Border> 135 <TextBlock Grid.Column="1" Text="{TemplateBinding Title}" Padding="5" Foreground="White" FontWeight="Bold" /> 136 <StackPanel Grid.Column="2" Orientation="Horizontal"> 137 <Button Margin="0" Name="MiniButton" Width="34" Template="{StaticResource MiniButton}" WindowChrome.IsHitTestVisibleInChrome="True" Command="{x:Static SystemCommands.MinimizeWindowCommand}" /> 138 <Button Name="MaxButton" Width="34" Style="{StaticResource WinNormalButton}" WindowChrome.IsHitTestVisibleInChrome="True" Command="{x:Static SystemCommands.MaximizeWindowCommand}" /> 139 <Button Name="CloseButton" Width="34" Style="{StaticResource CloseButton}" WindowChrome.IsHitTestVisibleInChrome="True" Command="{x:Static SystemCommands.CloseWindowCommand}" /> 140 </StackPanel> 141 </Grid> 142 </Border> 143 144 <Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="Black"> 145 <Border.Effect> 146 <!--<DropShadowEffect Direction="270" ShadowDepth="1" />--> 147 <BlurEffect /> 148 </Border.Effect> 149 </Border> 150 151 <Border Grid.Row="1" Background="White"> 152 <AdornerDecorator> 153 <ContentPresenter /> 154 </AdornerDecorator> 155 </Border> 156 157 </Grid> 158 159 </Border> 160 </ControlTemplate> 161 </Setter.Value> 162 </Setter> 163 </Style> 164 165 </ResourceDictionary>
1 using System.Windows; 2 using System.Windows.Input; 3 4 namespace AsNum.WPF.Controls { 5 public class StyleWindow : Window { 6 static StyleWindow() { 7 DefaultStyleKeyProperty.OverrideMetadata(typeof(StyleWindow), new FrameworkPropertyMetadata(typeof(StyleWindow))); 8 } 9 10 public StyleWindow() 11 : base() { 12 //绑定命令,配合自定义的最大化/最小化,关闭按钮 13 var showSysMenu = new CommandBinding(SystemCommands.ShowSystemMenuCommand, OnShowSystemMenuCommand); 14 this.CommandBindings.Add(showSysMenu); 15 16 var closeWindow = new CommandBinding(SystemCommands.CloseWindowCommand, OnCloseWindowCommand); 17 this.CommandBindings.Add(closeWindow); 18 19 var maxWindow = new CommandBinding(SystemCommands.MaximizeWindowCommand, OnMaximizeWindowCommand); 20 var restoreWindow = new CommandBinding(SystemCommands.RestoreWindowCommand, OnRestoreWindowCommand); 21 this.CommandBindings.Add(maxWindow); 22 this.CommandBindings.Add(restoreWindow); 23 24 var minWindow = new CommandBinding(SystemCommands.MinimizeWindowCommand, OnMinimizeWindowCommand); 25 this.CommandBindings.Add(minWindow); 26 27 FullScreenManager.RepairWpfWindowFullScreenBehavior(this); 28 } 29 30 private void OnMinimizeWindowCommand(object sender, ExecutedRoutedEventArgs e) { 31 var w = Window.GetWindow(this); 32 SystemCommands.MinimizeWindow(this); 33 } 34 35 private void MaxOrRestoreWindow() { 36 var w = Window.GetWindow(this); 37 //Action<Window> act = w.WindowState == System.Windows.WindowState.Maximized ? (w)=> SystemCommands.RestoreWindow(w) : (w)=>SystemCommands.MaximizeWindow(w); 38 if (w.WindowState == System.Windows.WindowState.Maximized) 39 SystemCommands.RestoreWindow(w); 40 else { 41 SystemCommands.MaximizeWindow(w); 42 } 43 } 44 45 private void OnRestoreWindowCommand(object sender, ExecutedRoutedEventArgs e) { 46 this.MaxOrRestoreWindow(); 47 } 48 49 private void OnMaximizeWindowCommand(object sender, ExecutedRoutedEventArgs e) { 50 this.MaxOrRestoreWindow(); 51 } 52 53 private void OnCloseWindowCommand(object sender, ExecutedRoutedEventArgs e) { 54 var w = Window.GetWindow(this); 55 SystemCommands.CloseWindow(w); 56 } 57 58 private void OnShowSystemMenuCommand(object sender, ExecutedRoutedEventArgs e) { 59 Window w = Window.GetWindow(this); 60 Point p = new Point(w.Left + 24, w.Top + 24); 61 62 SystemCommands.ShowSystemMenu(w, p); 63 } 64 } 65 }
画最小/大化,关闭按钮时, 一开始我用的是图片, 但是自己都赶脚不专业.
Path 有 Data 这个属性, 是个 Geometry , 但是它的语法太精简, 一时半会掌握不了, 怎么办呢? 网上看到有文章说如何用 Blend 导入PSD,并生成这个 Data, 不过说的我在 PS CS3 里根本就不怎么点!
摸索了一下,终于搞出来了.
1,用 PS 画个简单的图.
2, 建一个矢量蒙版, 按下图操作就是了.
3, 选中刚才画的那个简单的图形, 要出现一个选区 (至于要怎么选中才有这个选区,请招身边的PS师傅). 在路径选卡中, 将选区转换为路径.
4, 会是这个样子, 然后选中"工作路径", CTRL+X , 对,就是剪切.
5, 选中 适量蒙版, CTRL + V , 对,就是把工作路径弄到矢量蒙版上.
6,最后是这个样子, 保存为PSD
7, 在Blend 中导入 , 可以看到 Image 有个 Clip , 这个就是我们要的 Data.
就这样,不过有些图形生成的Data 过于庞大, 还不如直接拿现成的.
关闭/最大/最小这三个 Path 的 Data 其实是我用 Snoop 从 VS2013 中取的!
ScrollBar 更简单, 只需要在 Blend 里编织副本就行了,没有什么地方需要注意的.
1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 3 4 5 <SolidColorBrush x:Key="ScrollBar.Static.Background" Color="#F0F0F0"/> 6 <SolidColorBrush x:Key="ScrollBar.Static.Border" Color="#F0F0F0"/> 7 <SolidColorBrush x:Key="ScrollBar.Static.Glyph" Color="#000000"/> 8 9 <SolidColorBrush x:Key="ScrollBar.Pressed.Glyph" Color="#FFFFFF"/> 10 <SolidColorBrush x:Key="ScrollBar.Pressed.Background" Color="#606060"/> 11 <SolidColorBrush x:Key="ScrollBar.Pressed.Border" Color="#606060"/> 12 13 <SolidColorBrush x:Key="ScrollBar.MouseOver.Glyph" Color="#000000"/> 14 <SolidColorBrush x:Key="ScrollBar.MouseOver.Background" Color="#DADADA"/> 15 <SolidColorBrush x:Key="ScrollBar.MouseOver.Border" Color="#DADADA"/> 16 17 <SolidColorBrush x:Key="ScrollBar.Disabled.Glyph" Color="#000000"/> 18 <SolidColorBrush x:Key="ScrollBar.Disabled.Background" Color="Transparent"/> 19 <SolidColorBrush x:Key="ScrollBar.Disabled.Border" Color="Transparent"/> 20 21 <Style x:Key="FocusVisual"> 22 <Setter Property="Control.Template"> 23 <Setter.Value> 24 <ControlTemplate> 25 <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> 26 </ControlTemplate> 27 </Setter.Value> 28 </Setter> 29 </Style> 30 31 32 <Style x:Key="ScrollBarButton" TargetType="{x:Type RepeatButton}"> 33 <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> 34 <Setter Property="BorderThickness" Value="0"/> 35 <Setter Property="HorizontalContentAlignment" Value="Center"/> 36 <Setter Property="VerticalContentAlignment" Value="Center"/> 37 <Setter Property="Padding" Value="0"/> 38 <Setter Property="Focusable" Value="false"/> 39 <Setter Property="IsTabStop" Value="false"/> 40 <Setter Property="Template"> 41 <Setter.Value> 42 <ControlTemplate TargetType="{x:Type RepeatButton}"> 43 <Border x:Name="border" BorderBrush="{StaticResource ScrollBar.Static.Border}" BorderThickness="1" Background="{StaticResource ScrollBar.Static.Background}" SnapsToDevicePixels="true"> 44 <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 45 </Border> 46 <ControlTemplate.Triggers> 47 <Trigger Property="IsMouseOver" Value="true"> 48 <Setter Property="Background" TargetName="border" Value="{StaticResource ScrollBar.MouseOver.Background}"/> 49 <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ScrollBar.MouseOver.Border}"/> 50 </Trigger> 51 <Trigger Property="IsPressed" Value="true"> 52 <Setter Property="Background" TargetName="border" Value="{StaticResource ScrollBar.Pressed.Background}"/> 53 <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ScrollBar.Pressed.Border}"/> 54 </Trigger> 55 <Trigger Property="IsEnabled" Value="false"> 56 <Setter Property="Opacity" TargetName="contentPresenter" Value="0.56"/> 57 <Setter Property="Background" TargetName="border" Value="{StaticResource ScrollBar.Disabled.Background}"/> 58 <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ScrollBar.Disabled.Border}"/> 59 </Trigger> 60 </ControlTemplate.Triggers> 61 </ControlTemplate> 62 </Setter.Value> 63 </Setter> 64 </Style> 65 66 <Style x:Key="RepeatButtonTransparent" TargetType="{x:Type RepeatButton}"> 67 <Setter Property="OverridesDefaultStyle" Value="true"/> 68 <Setter Property="Background" Value="Transparent"/> 69 <Setter Property="Focusable" Value="false"/> 70 <Setter Property="IsTabStop" Value="false"/> 71 <Setter Property="Template"> 72 <Setter.Value> 73 <ControlTemplate TargetType="{x:Type RepeatButton}"> 74 <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/> 75 </ControlTemplate> 76 </Setter.Value> 77 </Setter> 78 </Style> 79 80 <SolidColorBrush x:Key="ScrollBar.MouseOver.Thumb" Color="#CDCDCD"/> 81 <SolidColorBrush x:Key="ScrollBar.Pressed.Thumb" Color="#606060"/> 82 <SolidColorBrush x:Key="ScrollBar.Static.Thumb" Color="#A6A6A6"/> 83 84 <Style x:Key="ScrollBarThumbVertical" TargetType="{x:Type Thumb}"> 85 <Setter Property="OverridesDefaultStyle" Value="true"/> 86 <Setter Property="IsTabStop" Value="false"/> 87 <Setter Property="Template"> 88 <Setter.Value> 89 <ControlTemplate TargetType="{x:Type Thumb}"> 90 <Rectangle RadiusX="5" RadiusY="5" x:Name="rectangle" Fill="{StaticResource ScrollBar.Static.Thumb}" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="{TemplateBinding Width}"/> 91 <ControlTemplate.Triggers> 92 <Trigger Property="IsMouseOver" Value="true"> 93 <Setter Property="Fill" TargetName="rectangle" Value="{StaticResource ScrollBar.MouseOver.Thumb}"/> 94 </Trigger> 95 <Trigger Property="IsDragging" Value="true"> 96 <Setter Property="Fill" TargetName="rectangle" Value="{StaticResource ScrollBar.Pressed.Thumb}"/> 97 </Trigger> 98 </ControlTemplate.Triggers> 99 </ControlTemplate> 100 </Setter.Value> 101 </Setter> 102 </Style> 103 <Style x:Key="ScrollBarThumbHorizontal" TargetType="{x:Type Thumb}"> 104 <Setter Property="OverridesDefaultStyle" Value="true"/> 105 <Setter Property="IsTabStop" Value="false"/> 106 <Setter Property="Template"> 107 <Setter.Value> 108 <ControlTemplate TargetType="{x:Type Thumb}"> 109 <Rectangle RadiusX="5" RadiusY="5" x:Name="rectangle" Fill="{StaticResource ScrollBar.Static.Thumb}" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="{TemplateBinding Width}"/> 110 <ControlTemplate.Triggers> 111 <Trigger Property="IsMouseOver" Value="true"> 112 <Setter Property="Fill" TargetName="rectangle" Value="{StaticResource ScrollBar.MouseOver.Thumb}"/> 113 </Trigger> 114 <Trigger Property="IsDragging" Value="true"> 115 <Setter Property="Fill" TargetName="rectangle" Value="{StaticResource ScrollBar.Pressed.Thumb}"/> 116 </Trigger> 117 </ControlTemplate.Triggers> 118 </ControlTemplate> 119 </Setter.Value> 120 </Setter> 121 </Style> 122 123 <Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource {x:Type ScrollBar}}"> 124 <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/> 125 <Setter Property="Stylus.IsFlicksEnabled" Value="false"/> 126 <Setter Property="Background" Value="{StaticResource ScrollBar.Static.Background}"/> 127 <Setter Property="BorderBrush" Value="{StaticResource ScrollBar.Static.Border}"/> 128 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 129 <Setter Property="BorderThickness" Value="1,0"/> 130 <Setter Property="Width" Value="8"/> 131 <Setter Property="MinWidth" Value="8"/> 132 <Setter Property="Template"> 133 <Setter.Value> 134 <ControlTemplate TargetType="{x:Type ScrollBar}"> 135 <Grid x:Name="Bg" SnapsToDevicePixels="true"> 136 <Grid.RowDefinitions> 137 <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/> 138 <RowDefinition Height="0.00001*"/> 139 <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/> 140 </Grid.RowDefinitions> 141 <!--<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Row="1"/>--> 142 <RepeatButton x:Name="PART_LineUpButton" Command="{x:Static ScrollBar.LineUpCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Style="{StaticResource ScrollBarButton}"> 143 <Path x:Name="ArrowTop" Data="M 0,4 C0,4 0,6 0,6 0,6 3.5,2.5 3.5,2.5 3.5,2.5 7,6 7,6 7,6 7,4 7,4 7,4 3.5,0.5 3.5,0.5 3.5,0.5 0,4 0,4 z" Fill="{StaticResource ScrollBar.Static.Glyph}" Stretch="Uniform"/> 144 </RepeatButton> 145 <Track x:Name="PART_Track" IsDirectionReversed="true" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="1"> 146 <Track.DecreaseRepeatButton> 147 <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}" Style="{StaticResource RepeatButtonTransparent}"/> 148 </Track.DecreaseRepeatButton> 149 <Track.IncreaseRepeatButton> 150 <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}" Style="{StaticResource RepeatButtonTransparent}"/> 151 </Track.IncreaseRepeatButton> 152 <Track.Thumb> 153 <Thumb Style="{StaticResource ScrollBarThumbVertical}"/> 154 </Track.Thumb> 155 </Track> 156 <RepeatButton x:Name="PART_LineDownButton" Command="{x:Static ScrollBar.LineDownCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="2" Style="{StaticResource ScrollBarButton}"> 157 <Path x:Name="ArrowBottom" Data="M 0,2.5 C0,2.5 0,0.5 0,0.5 0,0.5 3.5,4 3.5,4 3.5,4 7,0.5 7,0.5 7,0.5 7,2.5 7,2.5 7,2.5 3.5,6 3.5,6 3.5,6 0,2.5 0,2.5 z" Fill="{StaticResource ScrollBar.Static.Glyph}" Stretch="Uniform"/> 158 </RepeatButton> 159 </Grid> 160 <ControlTemplate.Triggers> 161 <MultiDataTrigger> 162 <MultiDataTrigger.Conditions> 163 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineDownButton}" Value="true"/> 164 <Condition Binding="{Binding IsPressed, ElementName=PART_LineDownButton}" Value="true"/> 165 </MultiDataTrigger.Conditions> 166 <Setter Property="Fill" TargetName="ArrowBottom" Value="{StaticResource ScrollBar.Pressed.Glyph}"/> 167 </MultiDataTrigger> 168 <MultiDataTrigger> 169 <MultiDataTrigger.Conditions> 170 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineUpButton}" Value="true"/> 171 <Condition Binding="{Binding IsPressed, ElementName=PART_LineUpButton}" Value="true"/> 172 </MultiDataTrigger.Conditions> 173 <Setter Property="Fill" TargetName="ArrowTop" Value="{StaticResource ScrollBar.Pressed.Glyph}"/> 174 </MultiDataTrigger> 175 <MultiDataTrigger> 176 <MultiDataTrigger.Conditions> 177 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineDownButton}" Value="true"/> 178 <Condition Binding="{Binding IsPressed, ElementName=PART_LineDownButton}" Value="false"/> 179 </MultiDataTrigger.Conditions> 180 <Setter Property="Fill" TargetName="ArrowBottom" Value="{StaticResource ScrollBar.MouseOver.Glyph}"/> 181 </MultiDataTrigger> 182 <MultiDataTrigger> 183 <MultiDataTrigger.Conditions> 184 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineUpButton}" Value="true"/> 185 <Condition Binding="{Binding IsPressed, ElementName=PART_LineUpButton}" Value="false"/> 186 </MultiDataTrigger.Conditions> 187 <Setter Property="Fill" TargetName="ArrowTop" Value="{StaticResource ScrollBar.MouseOver.Glyph}"/> 188 </MultiDataTrigger> 189 <Trigger Property="IsEnabled" Value="false"> 190 <Setter Property="Fill" TargetName="ArrowTop" Value="{StaticResource ScrollBar.Disabled.Glyph}"/> 191 <Setter Property="Fill" TargetName="ArrowBottom" Value="{StaticResource ScrollBar.Disabled.Glyph}"/> 192 </Trigger> 193 </ControlTemplate.Triggers> 194 </ControlTemplate> 195 </Setter.Value> 196 </Setter> 197 <Style.Triggers> 198 <Trigger Property="Orientation" Value="Horizontal"> 199 <Setter Property="Width" Value="Auto"/> 200 <Setter Property="MinWidth" Value="0"/> 201 <Setter Property="Height" Value="8"/> 202 <Setter Property="MinHeight" Value="8"/> 203 <Setter Property="BorderThickness" Value="0,1"/> 204 <Setter Property="Template"> 205 <Setter.Value> 206 <ControlTemplate TargetType="{x:Type ScrollBar}"> 207 <Grid x:Name="Bg" SnapsToDevicePixels="true"> 208 <Grid.ColumnDefinitions> 209 <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/> 210 <ColumnDefinition Width="0.00001*"/> 211 <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/> 212 </Grid.ColumnDefinitions> 213 <!--<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1"/>--> 214 <RepeatButton x:Name="PART_LineLeftButton" Command="{x:Static ScrollBar.LineLeftCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Style="{StaticResource ScrollBarButton}"> 215 <Path x:Name="ArrowLeft" Data="M 3.18,7 C3.18,7 5,7 5,7 5,7 1.81,3.5 1.81,3.5 1.81,3.5 5,0 5,0 5,0 3.18,0 3.18,0 3.18,0 0,3.5 0,3.5 0,3.5 3.18,7 3.18,7 z" Fill="{StaticResource ScrollBar.Static.Glyph}" Stretch="Uniform"/> 216 </RepeatButton> 217 <Track x:Name="PART_Track" Grid.Column="1" IsEnabled="{TemplateBinding IsMouseOver}"> 218 <Track.DecreaseRepeatButton> 219 <RepeatButton Command="{x:Static ScrollBar.PageLeftCommand}" Style="{StaticResource RepeatButtonTransparent}"/> 220 </Track.DecreaseRepeatButton> 221 <Track.IncreaseRepeatButton> 222 <RepeatButton Command="{x:Static ScrollBar.PageRightCommand}" Style="{StaticResource RepeatButtonTransparent}"/> 223 </Track.IncreaseRepeatButton> 224 <Track.Thumb> 225 <Thumb Style="{StaticResource ScrollBarThumbHorizontal}"/> 226 </Track.Thumb> 227 </Track> 228 <RepeatButton x:Name="PART_LineRightButton" Grid.Column="2" Command="{x:Static ScrollBar.LineRightCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Style="{StaticResource ScrollBarButton}"> 229 <Path x:Name="ArrowRight" Data="M 1.81,7 C1.81,7 0,7 0,7 0,7 3.18,3.5 3.18,3.5 3.18,3.5 0,0 0,0 0,0 1.81,0 1.81,0 1.81,0 5,3.5 5,3.5 5,3.5 1.81,7 1.81,7 z" Fill="{StaticResource ScrollBar.Static.Glyph}" Stretch="Uniform"/> 230 </RepeatButton> 231 </Grid> 232 <ControlTemplate.Triggers> 233 <MultiDataTrigger> 234 <MultiDataTrigger.Conditions> 235 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineRightButton}" Value="true"/> 236 <Condition Binding="{Binding IsPressed, ElementName=PART_LineRightButton}" Value="true"/> 237 </MultiDataTrigger.Conditions> 238 <Setter Property="Fill" TargetName="ArrowRight" Value="{StaticResource ScrollBar.Pressed.Glyph}"/> 239 </MultiDataTrigger> 240 <MultiDataTrigger> 241 <MultiDataTrigger.Conditions> 242 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineLeftButton}" Value="true"/> 243 <Condition Binding="{Binding IsPressed, ElementName=PART_LineLeftButton}" Value="true"/> 244 </MultiDataTrigger.Conditions> 245 <Setter Property="Fill" TargetName="ArrowLeft" Value="{StaticResource ScrollBar.Pressed.Glyph}"/> 246 </MultiDataTrigger> 247 <MultiDataTrigger> 248 <MultiDataTrigger.Conditions> 249 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineRightButton}" Value="true"/> 250 <Condition Binding="{Binding IsPressed, ElementName=PART_LineRightButton}" Value="false"/> 251 </MultiDataTrigger.Conditions> 252 <Setter Property="Fill" TargetName="ArrowRight" Value="{StaticResource ScrollBar.MouseOver.Glyph}"/> 253 </MultiDataTrigger> 254 <MultiDataTrigger> 255 <MultiDataTrigger.Conditions> 256 <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineLeftButton}" Value="true"/> 257 <Condition Binding="{Binding IsPressed, ElementName=PART_LineLeftButton}" Value="false"/> 258 </MultiDataTrigger.Conditions> 259 <Setter Property="Fill" TargetName="ArrowLeft" Value="{StaticResource ScrollBar.MouseOver.Glyph}"/> 260 </MultiDataTrigger> 261 <Trigger Property="IsEnabled" Value="false"> 262 <Setter Property="Fill" TargetName="ArrowLeft" Value="{StaticResource ScrollBar.Disabled.Glyph}"/> 263 <Setter Property="Fill" TargetName="ArrowRight" Value="{StaticResource ScrollBar.Disabled.Glyph}"/> 264 </Trigger> 265 </ControlTemplate.Triggers> 266 </ControlTemplate> 267 </Setter.Value> 268 </Setter> 269 </Trigger> 270 </Style.Triggers> 271 </Style> 272 273 274 </ResourceDictionary>
另外, 附上本文和前文所说的东西.
http://files.cnblogs.com/xling/AsNum.WPF.Controls.7z