admin管理员组文章数量:1589747
使用 Interaction 里面的方法来将事件映射到ViewModel层
引用命名空间:System.Windows.Interactivity.dll
在xaml界面引用这两种任意一个就行,这两个做的事情是相同的。
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:i="http://schemas.microsoft/expression/2010/interactivity"
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="MainWindow" Height="350" Width="525">
<!--xmlns:i="http://schemas.microsoft/expression/2010/interactivity"-->
<!--页面加载命令-->
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding Page_Loaded}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<i:Interaction.Behaviors>
<c:WindowBehavior Close="{Binding ToClose}" />
</i:Interaction.Behaviors>
<Grid>
<ComboBox x:Name="cb_kaname" IsReadOnly="False" BorderThickness="1" BorderBrush="#999999" ItemsSource="{Binding lst_KaLei, Mode=TwoWay}" SelectedItem="{Binding Sel_Kalei, Mode=TwoWay}" Text="{Binding new_ka_name, Mode=TwoWay}" DisplayMemberPath="ka_name" Width="Auto" MinWidth="80" MaxWidth="200" IsEditable="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding cb_kaname_SelectionChanged}" CommandParameter="{Binding ElementName=cb_kaname}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<TextBox Name="tb_dazhebilvamount" Background="Transparent" Style="{StaticResource input_textbox}" MaxLength="3" HorizontalContentAlignment="Center" Text="{Binding new_faka_dazhebilv, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<intr:Interaction.Triggers>
<intr:EventTrigger EventName="TextChanged">
<intr:InvokeCommandAction Command="{Binding txt_TextChanged,TargetNullValue='has error'}" CommandParameter="tb_dazhebilvamount" ></intr:InvokeCommandAction>
</intr:EventTrigger>
<intr:EventTrigger EventName="GotFocus">
<intr:InvokeCommandAction Command="{Binding txt_GotFocus}"></intr:InvokeCommandAction>
</intr:EventTrigger>
<intr:EventTrigger EventName="LostFocus">
<intr:InvokeCommandAction Command="{Binding txt_LostFocus}"></intr:InvokeCommandAction>
</intr:EventTrigger>
</intr:Interaction.Triggers>
</TextBox>
<Button x:Name="btnLogin" Content="登 录" Width="100" FontSize="20" Margin="10" Style="{StaticResource btnOK}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding btnLogin}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</Window>
个人记录,介绍并不完善,只有几个使用案例,仅供参考。
本文标签: WPFInteraction
版权声明:本文标题:WPF Interaction 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728077117a1144623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论