How to convert string to ViewModel object? #377
Unanswered
jsimunac01
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Such use of strings instead of types, or "stringy-typed", is usually discouraged - you lose any compile-time help the compiler can give you, and errors will appear at runtime instead. That said, you could use a dictionary to map between the string and the type, or use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've got a reporting dashboard. When the user clicks a button, it opens the correct viewmodel and displays the view. So button1 open VM1ViewModel, button2 opens VM2ViewModel, etc. This means that all possible viewmodels are hard coded in the program. I would like to store the viewmodel names in the database (with the rest of the user interface information). That is stored as a string. So for button1 I would pass "VM1ViewModel" as string. Now I need to open it with WindowManager.ShowWindow(new VM1ViewModel). If I just type the name, no problem. But I can't use the string. I've tried converting to a Screen object, but I can't find any way to convert from a string to Screen. Is this even possible? If so, how would I go about it. Google is being singularly unhelpful on this one. Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions