【发布时间】:2010-11-13 09:32:00
【问题描述】:
我在 XAML 文件中有一个文本框,在更改文本框中的文本时,不会调用 prop setter。我能够在 ProjectOfficer 文本框中获取值,但无法更新它。我正在使用 MVVM 模式
下面是我的代码 XAML
TextBox Text="{Binding Path=Officer,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
x:Name="ProjectOfficer"/>
ViewModel.cs
public Staff Officer
{
get
{
return __con.PrimaryOfficer ;
}
set
{
_con.PrimaryOfficer = value;
_con.PrimaryOfficer.Update(true);
}
}
Staff.cs
public class Staff : EntityBase
{
public Staff();
public string Address { get; }
public string Code { get; set; }
public override void Update();
}
谢谢
【问题讨论】:
-
由于类型不匹配,这绝对是一个绑定问题。对于这种事情,您应该始终关注 VS 中的输出窗口。此外,使用此链接进行一般绑定诊断:bea.stollnitz.com/blog/?p=52
-
+1 安德森,尤其是 mvvm 模式