WPF中按钮悬停图像的问题

时间:2016-02-22 23:48:19

标签: wpf vb.net

我正试图在鼠标悬停时更改按钮图像,我似乎无法使其工作。我已经完成了当按钮悬停时无法显示蓝色色调但现在无法更改图像。我在这里阅读了很多帖子,并按照其他例子,但不能使它工作。当我使用下面的代码并将鼠标悬停在按钮上时,图像保持不变,并且不会更改为指定的新图像。想法?

蓝色色调去除

   <Window.Resources>
    <Style x:Key="ButtonStyleNoHighlighting" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

按钮悬停图像

<Button x:Name="btnCloseApp" 
        Click="Application_Close"  
        Style="{StaticResource ButtonStyleNoHighlighting}">

        <Button.Background>
            <ImageBrush ImageSource="Resources/BTN_Close.png"/>
        </Button.Background>

        <Button.Resources>
            <ControlTemplate x:Key="BackgroundButton" TargetType="Button">
                <Border Name="border" BorderThickness="1" BorderBrush="Black" Background="{TemplateBinding Background}">
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background">
                            <Setter.Value>
                                <ImageBrush ImageSource="Resources/BTN_Close_Hover.png" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Resources>
    </Button>

非常感谢任何帮助!

0 个答案:

没有答案