简体   繁体   English

具有图像蓝色背景的按钮

[英]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 在这里,替代方法不知道c#有什么更好的方法,您所要做的就是再添加两个eventHndlers Mouse over event和press event,然后在它们两个中都设置图像。这样做的另一种好方法是尝试从blend软件编辑模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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