I’m building a Silverlight app and I would like to disable a button while a long running operation is going on in the background.
I’m using MVVM, so in the ViewModel I have a property called SearchInProgress.
Now I would like to disable the search button whenever SearchInProgress in true.
In WPF I would simply write a DataTrigger which sets IsEnabled on the search button to false.
Sadly DataTriggers are not available in Silverlight, so I’m looking for another solution. I’ve tried toying around with the VisualStateManager but I haven’t gotten anywhere. The VSM seems like overkill for this simple thing I’m trying to achieve.
Any help is appreciated.
I’ve found a solution that I am quite happy with.
First I defined two VSM states on my LayoutRoot Grid ‘SearchInProgress’ and ‘Normal’.
Pretty simplistic and I might adapt them but it works.
To switch between the states I use the DataStateBehavior from here which lets me bind to a Property on the datacontext (viewmodel) and switch between two states accordingly:
I think I’m now able to use the power of the VSM, designability in Blend and the flexibility of the ‘DataTrigger’ mechanism to full effect.