首页 > 解决方案 > 如何从 ViewModel 触发“完成”事件?

问题描述

我有一个完整的动作条目:

 <local:BaseEntry Placeholder="Email Address" Keyboard="Email"     x:Name="EmailEntry" ReturnType="Next" Completed="{Binding GoToPassword}"/>

当用户从键盘按下完成按钮时,我想专注于下一个条目。那么如何从 ViewModel 执行 Completed 操作呢?

标签: xamarinxamarin.forms

解决方案


那么如何从 ViewModel 执行 Completed 操作呢?

在 Xaml 中使用ReturnCommandandReturnType而不是:Completed

<local:BaseEntry Placeholder="Email Address" Keyboard="Email" x:Name="EmailEntry" ReturnType="Next" ReturnCommand="{Binding CommandComplete}" ReturnType="Done"/>

然后在ViewModel添加CommandComplete属性:

 public System.Windows.Input.ICommand CommandComplete { get; set; }

 CommandComplete = new Command(() => { Console.WriteLine("Complete method"); });

推荐阅读