WPF Button奇怪的焦点行为

时间:2011-08-16 10:41:54

标签: wpf image button focus

我已经搜遍了所有人的答案并阅读了很多关于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>

感谢您的任何意见。

3 个答案:

答案 0 :(得分:0)

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

试试这个

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

答案 1 :(得分:0)

你可以试试这个

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

答案 2 :(得分:0)

单独指定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>