1. 程式人生 > >WPF 通過行為將事件繫結到命令

WPF 通過行為將事件繫結到命令

dll:Microsoft.Expression.Interactions.dll

        System.Windows.Interactivity.dll

<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"
        xmlns:local="clr-namespace:Behavior"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
        xmlns:pi="http://schemas.microsoft.com/prototyping/2010/interactivity" 
        x:Class="Behavior.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="grid">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="17.5" Margin="141,73.5,0,0" VerticalAlignment="Top" Width="47.5">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter">
                    <i:InvokeCommandAction Command="{Binding  Path= EnterCommand}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeave">
                    <i:InvokeCommandAction Command="{Binding Path=LeaveCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </Grid>
</Window>