【问题标题】:WPF Button strange focus behaviorWPF按钮奇怪的焦点行为
【发布时间】:2011-08-16 10:41:53
【问题描述】:

我已经到处寻找这个问题的答案,并阅读了很多关于 SO 的帖子,但无济于事。

这是 VS10,.Net 4.0,标准按钮,带有图像作为背景和文本。我已经删除了非必要的属性。当鼠标进入按钮时,图像被一个灰色的大矩形替换/覆盖,中间是文本(“商店”)。

我已尝试更改大多数属性,包括。将 FocusVisualStyle 设置为 Style 和 null。

有什么想法吗?


<Button 
  BorderThickness="0" Content="Shop" Focusable="False" 
  Foreground="Black" Name="buttonShop" OverridesDefaultStyle="False" 
  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" 
  ClickMode="Release" IsEnabled="True" 
  IsHitTestVisible="True" isManipulationEnabled="True">                 
 <Button.Background>
  ImageBrush ImageSource="/button-green.png" 
 </Button.Background>
</Button>

感谢您的任何意见。

【问题讨论】:

    标签: wpf image button focus


    【解决方案1】:

    您的问题是您将背景设置为图像

    试试这个

    <Button .......>
       <Image Source ...... />
    </Button>
    

    【讨论】:

    • 是的,这行得通,但按钮只能有 1 个内容 - 我需要里面的文本。
    【解决方案2】:

    你可以试试这个

    <Button>
      <Button.Background>
        <ImageBrush ImageSource="Images/exemple.ico">
        </ImageBrush>
      </Button.Background>
    </Button>
    

    【讨论】:

      【解决方案3】:

      单独指定ToolBar.ButtonStyleKey

      <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="Button">
        <Setter Property="Foreground" Value="Blue"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
      </Style>
      

      【讨论】:

        猜你喜欢
        • 2012-08-11
        • 1970-01-01
        • 1970-01-01
        • 2015-03-22
        • 1970-01-01
        • 2020-01-15
        • 1970-01-01
        • 1970-01-01
        • 2011-11-27
        相关资源
        最近更新 更多