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