I have a requirement wherein I need to display on a User form, a Create Button if that user has doesnt have a profile and a Edit Button if he does have a profile. I am using a converter to change the visibility of the button.
Everything works fine initially, but the moment I click on the Create Profile window, and it is the constructor that loads the profile window, after that even if I close that window without doing anything, the Create button turns to edit. My guess is that, it is because the constructor would have create the profile object and so even though the object is empty it shows me edit button instead of create. Is there any other way I could display button visibility??
I have a requirement wherein I need to display on a User form, a
Share
Do you really need to alter the button’s visibility? This is not generally a great user-experience practice as it can confuse people about what they need to do next.
To simply disable the button, you could add logic to the
local:LaunchEditorcommand’sCanExecutemethod. There’s also aCanExecuteChangedevent which allows the UI to dynamically respond to changes in the command’s accessibility. This may be the easiest thing to do.If you really need to hide the button, then you can probably create a style with a trigger based on the button’s
IsEnabledproperty which will make the button’s visibilityHiddenwhenIsEnabled==false. You should, however, still use the command to control the accessibility of the button.In your case, you would write two methods:
CanCreateProfileandCanEditProfile, and include these in your command binding (either in XAML or in the codebehind):