ViewModel support in portable class library

I am testing PCL in a VS 2010 project in which I would like to support WPF (4 and above) and Silverlight (4 and above). The MS documentation below is confusing to me.

It seems to refer to System.Windows in a PCL project, but I don't see how to do it.

What should I do to have ICommand and INotifyPropertyChanged in my PCL project?

Support for the View Model template When you target Silverlight and Windows Phone 7, you can implement the model of the presentation model in your solution. Classes for implementing this template are located in System.Windows.dll from Silverlight. The System.Windows.dll assembly is not supported when creating a portable class library project designed for the .NET Framework 4 or Xbox 360.

Classes of this assembly include the following:

System.Collections.ObjectModel.ObservableCollection

System.Collections.ObjectModel.ReadOnlyObservableCollection

System.Collections.Specialized.INotifyCollectionChanged

System.Collections.Specialized.NotifyCollectionChangedAction

System.Collections.Specialized.NotifyCollectionChangedEventArgs

System.Collections.Specialized.NotifyCollectionChangedEventHandler

System.Windows.Input.ICommand

The .NET Framework 4 also contains these classes, but they are in assemblies other than System.Windows.dll. To use these classes with the Portable Project Library class, you must reference System.Windows.dll, not the assemblies listed in the .NET Framework 4 documentation

EDIT

INotifyPropertyChanged is not available; the code below will not compile

public abstract class ViewModelBase : INotifyPropertyChanged { public virtual event PropertyChangedEventHandler PropertyChanged; ... } 
+6
source share
1 answer

Yes, MSDN is confused at this point (is there an error?)

Basically, you have nothing to do!

You create your PCL project, just select the appropriate framework. new pcl project

PCL automatically manages links for you.

  public abstract class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } } 

Give it a try!

+2
source

Source: https://habr.com/ru/post/944127/


All Articles