I have a button which action can be take a lot of time. Is an async method, so in this way I don't block the UI, but also I would like to disabled the button to avoid the chance of execute another same action.
For that, I disabled the button and I change its background, to show that the action that is running is the action that I start when I click this button.
I have a converter, because in my View Model I have a bool property that set if the action has started or if the action has finished. To convert this bool to a background color I use a converter.
Well, the problem is that if I disabled the button, is not possible to set the background with the converter.
I would like to know how I can do this, disabled the button and change the backgrund with a converter.
My code in my view model
private async void componentesAsignar() { Bussy = true; //need for the converter, to set the background MyActionStarted = true; //need to disabled the button await Task.Delay(10000); //the code that takes many time }
My code in my view
<Button Content="MyAction" Height="23" Name="btnMyAction" Width="75" Background="{Binding MyActionStarted, Converter={StaticResource actionInProgressToColorConverter}}">
My converter
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(((bool)value) == false) { return "#FFDDDDDD"; } else { return "#FF589FF3"; } }
I am usgin Visual Studio 2013 Community and .NET 4.5.1.
Thank so much.