简体   繁体   中英

How to select a view from a viewmodel if different views share the same viewmodel

Since some of my views have similar functions, I want to be able to share the same viewmodel with each view. My idea is to pass a token to the viewmodel's constructor, but this will lead to many if and else statements in my code. Any ideas that I can avoid too many if else statement?

Use inheritance and datatemplate. Create a base class viewmodel and virtual functions. Override them with different functionality. Then use datatemplate to load the different views according to the view model you need.

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