您的位置:首页 > 其它

WPF 通过行为将事件绑定到命令

2016-11-30 20:29 459 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: