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

klr1opcd  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(169)

我想知道是否有一种方法可以将两个xaml文件绑定到一个viewmodel,以便允许从一个viewmodel到两个xaml文件的数据绑定。

oipij1gg

oipij1gg1#

这其实很简单

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

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

希望这对你有帮助

相关问题