wpf - 如何将 Themes/Generic.xaml 连接到 window1.xaml?

标签 wpf styles

我在 Themes/Generic.xaml 中有以下按钮样式,我希望它适用于我的 WPF 应用程序中随处可见的按钮。

例如,如何将它连接到我的 window1.xaml?

<Style TargetType="{x:Type Button}">
  <Setter Property="SnapsToDevicePixels" Value="true"/>
  <Setter Property="OverridesDefaultStyle" Value="true"/>
  <Setter Property="MinHeight" Value="23"/>
  <Setter Property="MinWidth" Value="75"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type Button}">
        <Border 
          x:Name="Border"  
          CornerRadius="2" 
          BorderThickness="1"
          Background="#C0C0C0"
          BorderBrush="#404040">
          <ContentPresenter 
            Margin="2"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            RecognizesAccessKey="True"/>
        </Border>
        <ControlTemplate.Triggers>
          <Trigger Property="IsKeyboardFocused" Value="true">
            <Setter TargetName="Border" Property="BorderBrush" Value="#202020" />
          </Trigger>
          <Trigger Property="IsDefaulted" Value="true">
            <Setter TargetName="Border" Property="BorderBrush" Value="#202020" />
          </Trigger>
          <Trigger Property="IsMouseOver" Value="true">
            <Setter TargetName="Border" Property="Background" Value="#808080" />
          </Trigger>
          <Trigger Property="IsPressed" Value="true">
            <Setter TargetName="Border" Property="Background" Value="#E0E0E0" />
            <Setter TargetName="Border" Property="BorderBrush" Value="#606060" />
          </Trigger>
          <Trigger Property="IsEnabled" Value="false">
            <Setter TargetName="Border" Property="Background" Value="#EEEEEE" />
            <Setter TargetName="Border" Property="BorderBrush" Value="#AAAAAA" />
            <Setter Property="Foreground" Value="#888888"/>
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

最佳答案

在您的 Widow1.xaml(或您的 App.xaml,更改为 )......

<Window1.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="DefaultStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window1.Resources>

关于wpf - 如何将 Themes/Generic.xaml 连接到 window1.xaml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/532513/

相关文章:

c# - 了解 PRISM 中的模块

wpf - 列表框选定文本颜色

wpf - 是否可以同时将 WPF 样式应用于不同类型?

javascript - 即使显示 :none 也为元素留出空间

wpf - 您知道使用MVVM的任何实际有用的WPF/Silverlight应用程序吗?

WPF如何在列表框失去焦点时更改列表框所选项目的文本颜色

android - 应用样式 Android

html - 如何阻止文本在表格中垂直居中?

c# - 将焦点设置在 UserControl 中的 TextBox 上

在调用已知会检查参数本身的函数之前检查参数