WPF鼠标悬停

时间:2013-09-03 03:43:15

标签: wpf vb.net

如果仍有按钮悬停并点击图片更改,请帮助我吗?这是我目前的代码:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="MOP_Launcher" mc:Ignorable="d" x:Class="MainWindow"
Title="MOP Launcher" Height="523" Width="977" WindowStyle="None" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Cursor="Arrow" Icon="pack://siteoforigin:,,,/mop.png" Foreground="{x:Null}" Visibility="Visible" AllowsTransparency="True">
<Window.Background>
    <ImageBrush ImageSource="pack://siteoforigin:,,,/MOP Launcher BG.png"/>
</Window.Background>
<Grid>
    <Button x:Name="playbtn" Content="Button" HorizontalAlignment="Left" Height="91" Margin="779,422,0,0" VerticalAlignment="Top" Width="165" Foreground="{x:Null}" BorderBrush="{x:Null}" Template="{DynamicResource ButtonControlTemplate2}" >
        <Button.Background>
            <ImageBrush ImageSource="play.png"/>

        </Button.Background>

    </Button>
</Grid>

1 个答案:

答案 0 :(得分:0)

您可以使用按钮样式更改图库,如下所示:

      <Button>
            <Button.Style>
                <Style TargetType="Button">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <ImageBrush ImageSource="play.png"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsMouseCaptureWithin" Value="true">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <ImageBrush ImageSource="pause.png"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>

由于