How to dynamically change control in mvvm
I have a开发者_JAVA技巧 main window, where are 3 buttons:
There are in grid.
Depending of loginname i want to switch one of them.
If user is in musician group the third button will have some musician image, and Command at click Open Musician Events
If user is in musician group the third button will have some musician image, and Command at click Open Cinema Events.
The simplest way for me is to set those properties by converters, but I don't want do it in this way. I want to have completely different controls.
How do you do that?
Not sure why you don't want to use Converters. However, if you insist on using completely different controls then why don't you simply bind the Visibility of the buttons to a property on the ViewModel e.g. Expose a property on the VM named IsCurrentUserInMusicians and bind the third buttons Visibility property to it. This way if the user is in the Musicians group then the appropriate button will be visible. If not it simply won't appear.
精彩评论