简体   繁体   English

如何使用 xamarin.forms 将两个 xaml 和 xaml.cs 文件绑定到一个 ViewModel?

[英]How to bind two xaml and xaml.cs files to one ViewModel using xamarin.forms?

I was wondering whether there is a way I could bind two xaml files to one viewmodel in order to allow data binding from one viewmodel to two xaml files.我想知道是否有一种方法可以将两个 xaml 文件绑定到一个视图模型,以便允许从一个视图模型将数据绑定到两个 xaml 文件。

That's really easy actually,其实真的很简单

SomePage somePage = new SomePage(); //View 1 
SomeOtherPage otherPage= new SomeOtherPage();  // View 2
YourCommonViewModel commonVm = new YourCommonViewModel(); //Common VM

somePage.BindingContext = commonVm;
otherPage.BindingContext= commonVm;

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM