I have started developing my first Windows Phone application as a freelancer for Romanian who lives in Finland (dream combination I guess). I developing the app (as well as all Silverlight/WPF apps) using the MVVM design pattern. I was a bit confused that the app is running normally on my HTC Windows Phone 8X as well as in the WP8 emulator but not on my Lumia 800 or WP7.1 emulator.
After some digging I have found what the problem was and it turns out to be a bit bizarre in my opinion. I haven’t added the public access modifier in before the class keyword. So in order to have your bindings work correctly this is how your viewmodel should look like when creating it.
public class ViewModel : NotificationObject { private string _foo; public string Foo { get { return _foo; } set { _foo = value; RaisePropertyChanged(()=> Foo); } } }
N.B. If you use commanding it’s wise to make the function public as well.
public class ViewModel : NotificationObject { private string _foo; public ViewModel() { BarCommand = new DelegateCommand(Bar); } public BarCommand { get; set;} public void Bar() { //Do something smart } public string Foo { get { return _foo; } set { _foo = value; RaisePropertyChanged(()=> Foo); } } }
If you define your commands like this you won’t get some strange/cryptic error messages
Until next time, don’t forget to be awesome