mvvm How to pass usercontrol from viewmodel to view | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

mvvm How to pass usercontrol from viewmodel to view

I have a class library that i am using in my viewmodel. For normal data (bool, int , string). This works fine. This class-library also contains a user control. I like to show this user-control in my main application. How can I create something in my viewmodel that allows me to refer to in my mainview

25th Feb 2020, 9:29 PM
sneeze
sneeze - avatar
4 Answers
+ 3
Use LiveData class inside viewmodel and observ that livedata in you activity or fragment
26th Feb 2020, 7:33 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 3
You mean you have class called library and you want to access that class inside your activity or fragment if yes than it possiable to observe this library class inside activity you just need one livedata that Contain library class as a genric parameter and after that you need to observe that livedata in your activity or fragment.
27th Feb 2020, 5:04 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Are you saying that you only can share data via a viewmodel. That is fine as long if you have one view and one viewmodel. I have a class-library with a usercontrol. I want to control, the way it behave and how it looks in de class library as independent self-controlled piece of UI. Is this possible with live data ? Do you have a link to a tutorial I like to read more about it.
26th Feb 2020, 8:56 PM
sneeze
sneeze - avatar
0
Is livedata just for android or also for wpf/windows desktop ?
27th Feb 2020, 9:16 PM
sneeze
sneeze - avatar