Reputation: 5279
I have wpf applicaton based on MVVM pattern. I have annoying issue and I can`t figure how can I solve it.
My application is wizard application, When the user press "Next" I am starting some progress in another thread (backgroundworker), when the bgWorker is starting he set CanMoveNext = false
which binded to Next button isEnabled property and when the bgworker is finish he set back CanMoveNext = true;
When CanMoveNext
get IsEnabled = false
the UI show it immediately but after the isEnabled propery set back to true the UI do the refresh just after a mouse click or keyboard key press.
After Im changing the property I
m using OnPropertyChanged()
method, I even tried use CommandManager.InvalidateRequerySuggested();
but it`s still not get refreshed without mouseclick.
How can I solve this problem?
Here is my code:
public override bool CanMoveNext
{
get
{
return canMoveNext;
}
set
{
canMoveNext = value;
OnPropertyChanged("CanMoveNext");
}
}
public void StartProgress()
{
CanMoveNext = false;
InitBGworkers(out bgStartPersonalWorker);
bgStartPersonalWorker.RunWorkerAsync();
}
void bgStartPersonalWorker_DoWork(object sender, DoWorkEventArgs e)
{
DoStuff();
}
void bgStartPersonalWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
CanMoveNext = true;
//Even CommandManager.InvalidateRequerySuggested(); doen`t help
}
//Code from XAML
<Button Content="{Binding ButtonNextCaption}" IsEnabled="{Binding CanMoveNext, UpdateSourceTrigger=PropertyChanged}" Command="{Binding Path=NavigateNextCommand}" Margin="5,0,5,0" Width="100" Height="40" FontSize="14" FontWeight="Bold"/>
Thanks
Upvotes: 3
Views: 1115
Reputation: 5279
I figure how solve it:
Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() =>
{
CommandManager.InvalidateRequerySuggested();
}));
Upvotes: 1