全局按钮光标

Hot*_*otN 2 wpf xaml

有没有办法在应用程序级别为控件类型设置默认光标?我想说所有Button控件,无论它们是否具有特定样式,都有一个手形光标的默认光标,除非它在该按钮的个别样式规范中被覆盖.

这是一个具有自己样式的按钮的示例,我想覆盖默认值

<UserControl>
    <UserControl.Resources>
        <Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <!-- My button's custom content here -->
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Button x:Name="btnClose" Style="{DynamicResource CloseButtonStyle}"/>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

Eug*_*rda 9

将Application.Resources中的样式放在App.xaml文件中.

<Style TargetType="Button">
  <Setter Property="Cursor" Value="Hand"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

UPDATE

关于第3条评论:要实现这一点,您需要将控制模板保留在UserControl.Resources:

<ControlTemplate x:Key="CloseButtonTemplate" TargetType="{x:Type Button}">
   <Grid>
      <!-- My button's custom content here -->
   </Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

然后设置Template属性Button:

<Button Template="{DynamicResource CloseButtonTemplate}"/>
Run Code Online (Sandbox Code Playgroud)