简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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