簡體   English   中英

設置按鈕的背景圖像

[英]Setting a background image for a button

確實是愚蠢的問題,但是我已經通過XAML為按鈕設置了背景圖片。 但是,當我運行該應用程序並將其懸停時,它將更改為默認外觀。

我無法解決如何將鼠標懸停在上方嗎?

<Button x:Name="btnPlay" Content="Play" Canvas.Left="93" Canvas.Top="93" Width="183" 
            Click="button_Click" Height="84" FontFamily="Showcard Gothic" Cursor="Hand" BorderBrush="{x:Null}">
    <Button.Background>
        <ImageBrush ImageSource="Images/BlueButton.png"/>
    </Button.Background>
</Button>

這是此解決方案的修改。 考慮使用Background="{TemplateBinding Background}"BorderTemplate ,所以更新的Background中的Border時, Button的背景變化。

<Button x:Name="btnPlay" Content="Play" Canvas.Left="93" Canvas.Top="93" Width="183" 
        Click="button_Click"   Height="84" FontFamily="Showcard Gothic" Cursor="Hand" 
        BorderBrush="{x:Null}">
    <Button.Background>
        <ImageBrush ImageSource="/WpfApplication1;component/5.png" />
    </Button.Background>
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Border Name="border" Background="{TemplateBinding Background}"> <!--Consider this-->
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background">
                        <Setter.Value>
                            <ImageBrush ImageSource="/WpfApplication1;component/5.png" />
                        </Setter.Value>
                    </Setter>
                    <Setter Property="BorderBrush" Value="Black"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Button.Template>
</Button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM