Xamarin绑定EventHandler

问题描述 投票:-1回答:1

如何在xaml中将事件处理程序从xaml绑定到ViewModel:

<Entry Text="{Binding SecondName , Mode=TwoWay}"  Focused="{Binding FocusedEventhandler}" Completed="{Binding Compleated}">

如何在viewModel中获取事件处理程序操作?

xamarin mvvm data-binding
1个回答
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();  
}  

这只是概述,让您了解我们如何做到这一点。

© www.soinside.com 2019 - 2024. All rights reserved.