WPF设置全局控件样式

时间:2023-11-26 23:03:20

原文:WPF设置全局控件样式

方法:

在资源文件APP.XAML中添加如下资源


  1. <Application x:Class="_360UI.App"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. StartupUri="/View/StartWindow.xaml">
  5. <Application.Resources>
  6. <ResourceDictionary>
  7. <Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource DefaultScrollBar}"></Style>
  8. <Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource DefaultScrollViewer}"></Style>
  9. </ResourceDictionary.MergedDictionaries>
  10. </ResourceDictionary>
  11. </Application.Resources>
  12. </Application>

其中

<Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource DefaultScrollBar}"></Style>

 <Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource DefaultScrollViewer}"></Style>

部分设置了全局进度条的样式!其他控件设置默认样式类似;