按钮有图象蓝色背景

时间:2013-02-13 08:50:47

标签: c# silverlight windows-phone-7

我在我的应用中创建了一个带图片的按钮:

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

    }

1 个答案:

答案 0 :(得分:1)

因为您没有添加状态,所以有三种状态Normal,MouseOver,Pressed ...您必须为所有三种状态设置图像,以使其符合您的愿望。这里的替代方法,不知道c#可用的任何更好的方法,你所要做的就是在事件和按事件上再添加两个eventHndlers鼠标,然后在它们中设置图像.... 那么另一个好方法是尝试使用混合软件进行模板编辑