gpt4 book ai didi

wpf - 全局按钮光标

转载 作者:行者123 更新时间:2023-12-03 22:40:43 25 4
gpt4 key购买 nike

有没有办法在应用程序级别为控件类型设置默认光标?我想说的是,所有 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>

最佳答案

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

<Style TargetType="Button">
<Setter Property="Cursor" Value="Hand"/>
</Style>

更新

关于第三条评论:为此,您只需要在 UserControl.Resources 中保留您的控件模板:

<ControlTemplate x:Key="CloseButtonTemplate" TargetType="{x:Type Button}">
<Grid>
<!-- My button's custom content here -->
</Grid>
</ControlTemplate>

然后为 Button 设置 Template 属性:

<Button Template="{DynamicResource CloseButtonTemplate}"/>

关于wpf - 全局按钮光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9198675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com