添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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 I m 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
                return canMoveNext;
                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

Just a wild shot, but have you tried setting the property from the UI thread? e.g. Setting the CanMoveNext using a Dispatcher.Invoke? – Blachshma Nov 4, 2012 at 13:55
            Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() =>
                CommandManager.InvalidateRequerySuggested();
                Using method group: Application.Current.Dispatcher.BeginInvoke(new ThreadStart(CommandManager.InvalidateRequerySuggested));
– Eric Bole-Feysot
                May 20, 2015 at 11:38
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.