简体   繁体   中英

Button with image blue background

I create a button with image in my app:

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

And i noticed that when the user press the button all the button became blue and when i release the button i see it again. any idea how to fix it?

Edit:

This is the handler method:

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);
        }

    }

Because you didn't add the States, there are three states Normal, MouseOver, Pressed... You have to set the image for all three states, to make it work of your wish. Here the alternate to do so, didn't know about any better way available from c#, all you have to do is to add two more eventHndlers Mouse over event and press event, then set the image in both of them.... Well there's another good way to do so is try template editing from blend Software

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM