2011-08-16 112 views
0

我已經搜索了所有的答案,並閱讀了許多線程在SO無濟於事。WPF按鈕奇怪的焦點行爲

這是VS10,.Net 4.0,帶圖片作爲背景和文本的標準按鈕。我刪除了非必要的屬性。當鼠標進入按鈕時,圖像將被一個灰色的大矩形替換/覆蓋,中間有文字(「商店」)。

我試過改變大多數物業包括。將FocusVisualStyle設置爲樣式併爲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> 

感謝您的任何輸入。

回答

0

你的問題是,你的背景設置爲一個圖像

試試這個

<Button .......> 
    <Image Source ...... /> 
</Button> 
+0

是,th但是按鈕只能有1個內容 - 我需要裏面的文本。 – MikeL

0

你可以試試這個

<Button> 
    <Button.Background> 
    <ImageBrush ImageSource="Images/exemple.ico"> 
    </ImageBrush> 
    </Button.Background> 
</Button> 
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>