How to keep the background of a button the same while it is pressed? [duplicate]

我的未来我决定 提交于 2019-12-13 01:25:03

问题


Possible Duplicate:
WPF Button isPressed and isEnabled problem

Here is a snippet of code from an application that I am developing using WPF and XAML. What I am trying to do is get the button's background to stay the same color when it is clicked on by the user as it is when it is not clicked on by the user.

Note: There is an image in the button.

<Button Name="Button1" Background="#3852A4" Grid.Column="0" Grid.Row="0" Width="35" Height="35" HorizontalAlignment="Left" VerticalAlignment="Top" Click="swapGd1andGd2">
    <Button.Style>
        <Style>
            <Style.Triggers>
                <Trigger Property="Button.IsPressed" Value="True">
                    <Setter Property="Button.Background" Value="#3852A4" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
    <Image Source="Images/112_DownArrowShort_Grey_24x24_72.png" Width="24" Height="24" Stretch="Fill"></Image>
</Button>`

My question is, why doesn't this code produce the results that I want?


回答1:


In wpf buttons have a default template that overrides style values. See here for an example of how to change the value using a template.



来源:https://stackoverflow.com/questions/8977254/how-to-keep-the-background-of-a-button-the-same-while-it-is-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!