簡體   English   中英

具有圖像藍色背景的按鈕

[英]Button with image blue background

我在應用程序中創建一個帶有圖像的按鈕:

                <Button x:Name="favoriteButton" HorizontalAlignment="Left" VerticalAlignment="Top" Height="72" Width="99" Click="DidPressAddToFavorites" BorderBrush="{x:Null}" Foreground="{x:Null}">
                    <Button.Background>
                        <ImageBrush ImageSource="/Images/favouritesBWIcon@2x.png" Stretch="Uniform"/>
                    </Button.Background>
                </Button>

而且我注意到,當用戶按下按鈕時,所有按鈕都會變成藍色,而當我釋放按鈕時,我會再次看到它。 任何想法如何解決?

編輯:

這是處理程序方法:

private void DidPressAddToFavorites(object sender, RoutedEventArgs e)
    {
        if (favoriteRep.ExistInFavorites(currentItem) == true)
        {
            this.SetButtonWithImage(favoriteButton, "/Images/favouritesBWIcon@2x.png");
            favoriteRep.RemoveFromFavorites(currentItem);
        }
        else
        {
            this.SetButtonWithImage(favoriteButton, "/Images/favouritesIcon@2x.png");
            favoriteRep.AddToFavorites(currentItem);
        }

    }

因為未添加狀態,所以共有三種狀態:正常,鼠標懸停,按下...。您必須為所有三種狀態設置圖像,以使其按您的意願工作。 在這里,替代方法不知道c#有什么更好的方法,您所要做的就是再添加兩個eventHndlers Mouse over event和press event,然后在它們兩個中都設置圖像。這樣做的另一種好方法是嘗試從blend軟件編輯模板

暫無
暫無

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

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