【2016-11-15】【坚持学习】【Day26】【WPF 命令绑定到事件】

今天同事跟我说了已经有用的东西。express

System.Windows.Interativity 这个命名空间可让我在界面上将命令绑定到对应的事件上。解决了我一直的疑问,只有点击事件能够绑定??如今有答案了,显然不是!spa

代码:code

 引用 System.Windows.Interactivity.dll 程序集以后,在添加xmlns的引用以下:xml

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

 

<Window x:Class="MVVMLightDemo.MainWindow"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
     Title="MainWindow" Height="300" Width="300">
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <i:InvokeCommandAction Command="{Binding LoadData}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

 

Loaded 是window 的事件
LoadData是viewmodel的命令。
相关文章
相关标签/搜索