I set the datacontext dynamically in code. I would like a button on screen to be enabled/disabled depending if DataContext == null or not. I can do it in code when I assign the DataContext but it would be better if I can bind like that 🙂
I set the datacontext dynamically in code. I would like a button on screen
Share
You should be able to use a
DataTriggeron the button style to disable your button when theDataContextis null. The other option is to bind theIsEnabledproperty to theDataContextand use a value converter to returnfalseifDataContextis null andtrueotherwise.With trigger:
With converter:
Converter:
And use it