开发者

WPF Button strange focus behavior

开发者 https://www.devze.com 2023-03-28 15:14 出处:网络
I have searched all over for an answer to this and read many threads on SO to no avail. This is VS10, .Net 4.0, standard Button with a image as background and a text. I have removed non-essential pro

I have searched all over for an answer to this and read many threads on SO to no avail.

This is VS10, .Net 4.0, standard Button with a image as background and a text. I have removed non-essential properties. When the mouse enters the button, the image is replaced/overwritten by a big grey rectangle with the text ("Shop") in the middle.

I have tried changing most properties incl. setting FocusVisualStyle to Style and null.

Any ideas?


<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" isManip开发者_StackOverflow社区ulationEnabled="True">                 
 <Button.Background>
  ImageBrush ImageSource="/button-green.png" 
 </Button.Background>
</Button>

Thanks for any input.


Your problem is that your setting the Background to an Image

try this

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


You can try this

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


Specify the ToolBar.ButtonStyleKey separately

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消