如何避免视图模型的冗余 属性

How to avoid redundant property for view model

我有一个接口,我的模型和视图模型implement.I在接口中有一个列表属性,该模型作为列表实现,但由于某些原因,我需要在视图[=15]中使用可观察集合=] 我可以使用 observable 实现相同的 属性 collection.Here 是我的示例代码,

public  class MyObject
{
    public string Property1 { get; set; }
     public string Property1 { get; set; }
}

public interface IFoo
{
    List<MyObject> MyList { get; set; }
}


public class Model : IFoo
{
    private List<MyObject> mMyList;

    public List<MyObject> MyList
    {
        get { return mMyList; }
        set { mMyList = value; }
    }
}

public class ViewModel : IFoo
{

    // I want 
    //ObservableCollection<string> Mylist 
    //for view purpose,How can I use the same property from interface 


}

别这么苛刻了。在您的界面中,我是说。

public interface IFoo
{
    IList<MyObject> MyList { get; set; }
}

并在幕后使用 OC

ObservableCollection 实现了 IList,因此您可以轻松

public class Bar : IFoo
{
    public IList<MyObject> MyList {get; private set;}
    public Bar()
    {
        MyList = new ObservableCollection<MyObject>();   
    //snip

绑定将知道我们的秘密并采取相应行动。