lbugnion / mvvmlight

The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Windows 10 UWP, Windows Presentation Foundation (WPF), Silverlight, Windows Phone.
http://www.mvvmlight.net
MIT License
1.16k stars 311 forks source link

View not updated when setting properties from within RelayCommand execution #106

Open a-einstein opened 3 years ago

a-einstein commented 3 years ago

This is the first time I am using MvvmLight, so I hope I am not overlooking something obvious.

In my WPF ViewModel I have something like:

       private ICommand readFileCommand;
       public ICommand ReadFileCommand => readFileCommand ?? (readFileCommand = new RelayCommand(ReadFile));

       private void ReadFile()
       {
             FileMessage = "Message.";
       }

       private string fileMessage;
       public string FileMessage
       {
            get { return fileMessage; }
            set
            {
                //Set(ref fileMessage, value);

                fileMessage = value;
                RaisePropertyChanged();
            }
        }

I have a couple of problems with it.

In wondered if the called methods should be asynchronous, but that does not seem logical. I have not tried that yet as that does not really fit into what I want to achieve.

So what is happening? Am I overlooking something? Is this a limitation of the framework? Or is this a bug?

Thanks!

a-einstein commented 3 years ago

Unfortunately this project seems abandoned.

I have posted the problem on Stackoverflow. See the status THERE.

If someone has any addition here, that would still be appreciated.

robinTsl commented 3 years ago

May not be the issue but a couple of observations. Set will only call RaisePropertyChanged if the property value changes (check the bool response). If you want it raised every time use RaisePropertyChanged. The event may not be being raised until after the read file action if you are not yielding a thread. You would need to ensure your operation is not conducted on the UI thread to free that thread to update the UI. The read operation should be async or background worker or similar.