如何将事件处理程序从xaml绑定到ViewModel 在我的xamal中:
<Entry Text="{Binding SecondName , Mode=TwoWay}" Focused="{Binding FocusedEventhandler}" Completed="{Binding Compleated}">
如何在viewModel中获取事件处理程序动作?
答案 0 :(得分:0)
尝试这种方式
public class TestViewModel
{
public ICommand FocusedEventhandler { get; private set; }
public TestViewModel()
{
FocusedEventhandler = new Command(async () => await ShowContactList());
}
async Task ShowContactList()
{
//your code here
}
}
从页面调用ViewModel
public partial class TestPage: ContentPage {
public AddContact() {
InitializeComponent();
BindingContext = new TestViewModel();
}
这仅仅是概述,目的是让您了解我们如何做到这一点。