2015-10-16 113 views
-1

我试图让我的业务对象在MVVMLight中使用Set()方法实现INotifyPropertyChanged。这是我到目前为止有:使我的业务对象实现INotifyPropertyChanged

public class Person : ObservableObject 
{ 
    private readonly Entities.Person entity; 

    public Person() 
    { 
     entity = new Entities.Person(); 
    } 

    public int ID 
    { 
     get { return entity.Id; } 
     set { Set(() => ID, ref entity.Id, value); } 
    } 
} 

很显然,因为我的错误,我不能这样做: A property or indexer may not be passed as an out or ref parameter

我应该怎么办呢?我是否需要直接实施INotifyPropertyChanged还是有另一种方法来执行此操作?

+0

没有公认的答案真的有用吗?似乎不太可能。 –

+0

好吧,它摆脱了错误,我的代码编译。我会说这有帮助。 – Jake

+1

这不是相同的代码,它看起来不像是你所拥有的东西的替代品。 –

回答

1

尝试改变:

Set(() => ID, ref id , value); 

要:

var obj = entity.Id; 
Set(() => ID, ref obj, value); 
entity.Id=obj; 
0

问题是:entity.Id是属性。 您可以使用周围的工作:

set 
{ 
int id; 
Set(() => ID, ref id , value); 
entity.Id=id; 
} 
+0

这将无法更新控件...它有一个计时问题。 –

+0

Set()会在实体更新之前引发更改的事件。 –

相关问题