2012-02-08 74 views
2

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

回答

9

把风格低于Application.Resources在App.xaml文件的一个例子。

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

UPDATE

在关于第三评论: 要做到这一点,你需要离开只是你的控制模板UserControl.Resources

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

然后设置Template属性Button

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

这似乎不适用于我的按钮。我用一个按钮的例子编辑了我的问题,我添加了一个自定义样式,我希望继承游标值,以便能够提供解决方案的洞察。 – HotN 2012-02-08 18:38:44

+0

如果它不起作用,您可能需要检查您的解决方案的默认按钮的样式(如在答案中)。我的意思是,当您创建不带x:Key的样式时,只需指定类型 - 它将作为其定义范围的默认样式。我在检查临时项目后发布了这个答案。如果你创建临时解决方案,你可以自己检查一下,在MainWindow两个按钮中输入你的App.xaml中的答案并指定样式。 – 2012-02-08 20:21:44

+0

您是否介意在评论中发布临时解决方案的MainWindow代码?按照您的建议,我使用温度2按钮解决方案进行了试用。一个标准按钮,直接来自工具箱,与你的例子非常相称。在样式中指定了一个模板的按钮(如上面所示),在控件模板中使用矩形的简单示例时,仍然显示无手形光标。 – HotN 2012-02-08 23:13:23