2011-10-25 96 views
3

我命名的自定义WPF属性类“RFPGegevens”结合自定义属性类WPF

public class RFPGegevens 
{ 
    private string _klant; 
    public String Klant 
    { 
     get { return _klant; } 
     set { _klant = value; } 
    } 
} 

在我的ViewModel我有一个属性RFPGegevens

private RFPGegevens _rfpGegevens; 

    public RFPGegevens RfpGegevens 
    { 
     get 
     { 
      if (_rfpGegevens == null) 
       _rfpGegevens = new RFPGegevens(); 
      return _rfpGegevens; 
     } 
     set 
     { 
      _rfpGegevens = value; 
      base.RaisePropertyChangedEvent("RfpGegevens"); 
     } 
    } 

此属性填写正确,如果我调试是这样的结果:

enter image description here

在我看来,我绑定荷兰国际集团的财产“RFPGegevens”我的网

<Grid DataContext="{Binding RfpGegevens}"> 

的DataContext的,仍然如果我调试“Klant”属性字段填。

enter image description here

但正如我在查看绑定该物业我的文本框仍然是空的。

<TextBox Text="{Binding Klant, Mode=TwoWay}"/> 

我也试过,但没有任何事情似乎工作:

<TextBox Text="{Binding RFPGegevens.Klant, Mode=TwoWay}"/> 

不知道我在做什么错。
在此先感谢;)

+0

你在哪里调试get-accessor? TextBox-Binding是否确保它被WPF调用? VS中的输出窗口在运行时对绑定有什么看法? –

+0

您是否将windows datacontext绑定设置为正确? – jrb

+0

您的ViewModel是否实现INotifyPropertyChanged,我看到您正在调用base.RaisePropertyChanged。 – BigL

回答

1

两件事

<TextBox Text="{Binding Klant, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

public class RFPGegevens 
{ 
    private string _klant; 
    public String Klant 
    { 
     get { return _klant; } 
     set { 
       _klant = value; 
       //Raise the property changed event here 
      } 
    } 
} 
+0

不幸的是没有解决问题。 – jefsmi

1

尝试你需要实现INotifyPropertyChanged接口为您​​的自定义类也如下:

public class RFPGegevens : INotifyPropertyChanged 

和从属性的set访问器中提取propertychanged事件。

0

你忘了在INotifyPropertyChanged中添加继承关系