如何使用WPF中的命令连接到WPF中的viewmodel? [英] How to work with commands in WPF connecting to viewmodel in WPF?

查看:174
本文介绍了如何使用WPF中的命令连接到WPF中的viewmodel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我为textbox编写的下面的代码当我失去焦点它必须工作并使用idataerrorinfo.without使用命令检查验证如果我绑定viewmodel它的工作为evry更改元素ie..Everytime it going对于背景代码。如何使用命令。在失去对该控件的关注后,它必须检查验证。



我尝试过:



here is the below code i have written for textbox when i loss focus on it it must work and check for validation using idataerrorinfo.without using command if i bind viewmodel its working for evry change of element ie..every time its going to background code .here how to work with command .after lossing focus on that control it must check for validation.

What I have tried:

 <TextBox Grid.Row="2" Name="MN" Grid.Column="1" Width="200" Height="30" DataContext="{StaticResource ViewModel}"
Text="{Binding Mobilenumber,Mode=TwoWay}" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="LostFocus">
                    <i:InvokeCommandAction Command="{Binding Mobilenumber}" CommandParameter="{Binding ElementName=MN,Path=Text}" >

                    </i:InvokeCommandAction>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox>

推荐答案

您不需要命令来执行此操作,绑定将为您完成。您配置了TextBox绑定(默认情况下)以在失去焦点时更新viewmodel。



您可以在此处阅读更多内容: [ ^ ]
You don't need commands to do this, the binding will do it for you. You have the TextBox binding configured (by default) to update the viewmodel on loss of focus.

You can read more here: [^]


这篇关于如何使用WPF中的命令连接到WPF中的viewmodel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆