I am working on a Silverlight application using the V3 SP1 toolkit MVVM Light Toolkit.
My app is completely french / english. All user interface elements (buttons, tags, etc.) And all data (models). I need dynamic language switching, and this is fully implemented and works with anything coming from the resource file. I am struggling with ViewModels.
Models have language-specific parameters (DescriptionEn, DescriptionFr) and an additional call to the LocalizedDescription property, which uses the current culture to return a call to the language-specific property.
When the language changes (by pressing a button), I pick up and broadcast (via Messenger) an event with a changed property.
In each of my ViewModels, I register to receive a modified language property message.
I want to tell all ViewModel properties that something has changed.
From: http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx
The PropertyChanged event can indicate that all properties of an object have been changed using null or String.Empty as the property name in PropertyChangedEventArgs.
However, since the toolkit abstracts the creation of the modified event with RaisePropertyChanged (...), I cannot get this to work. I also examined the source of takeit and found that RaisePropertyChanged calls VerifyPropertyName (..), which in turn returns an error, this property does not belong to the ViewModel. I also noticed that the VerifyPropertyName method is attributed to Conditional ("DEBUG"), but even if I select the Release configuration, an ArgumentException ("Property not found") is still raised.
Does anyone know a way to make this work with the toolkit other than manually calling RaisePropertyChanged for each ViewModel property?
Subsequent:
Based on Simon's comment, I tried to create my own class that extends ViewModelBase. I looked at the source on CodePlex and decided to create one RaiseAllPropertyChanged () method. It will be just a copy of RaisePropertyChanged (string propertyName), but without a parameter and without calling VerifyPropertyName (...). I can not make it work. Here is what I have.
public class ViewModelBaseExtended : ViewModelBase { protected void RaiseAllPropertyChanged() { var handler = this.PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(String.Empty)); } } }
But I get a compiler error: The event 'GalaSoft.MvvmLight.ViewModelBase.PropertyChanged' can only appear on the left hand side of += or -= . This is a copy of the code that is used in ViewModelBase.
Can someone offer some tips on how to make this work?
Decision:
I copied all the code from ViewModelBase to a new class. Then I added the RaisePropertyChanged() method mentioned above, which creates an instance of the PropertyChangedEventArgs class using String.Empty . Now this is a new subclass for my ViewModels.
Thanks again to Simon for being ahead!