c# - 绑定(bind)自定义属性类 WPF

标签 c# wpf binding

我有一个名为“RFPGegevens”的自定义 WPF 属性类

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

在我的 ViewModel 中我有一个属性 RFPGevens

    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

在我的 View 中,我将属性“RFPGegevens”绑定(bind)到我的网格的数据上下文

<Grid DataContext="{Binding RfpGegevens}">

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

enter image description here

但是当我在 View 中绑定(bind)此属性时,我的文本框仍然是空的。

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

我也试过这个,但似乎没有任何效果:

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

不知道我做错了什么。
提前致谢;)

最佳答案

尝试两件事

<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
            }
    }
 }

关于c# - 绑定(bind)自定义属性类 WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7888956/

相关文章:

c# - WPF 依赖属性 - 数据绑定(bind)不起作用

jquery - 销毁 jquery 函数和我的对象之间的绑定(bind)?

c# - MAF 对比 MEF 对比 Prism

C# Backgroundwork 在抛出异常时不调用 e.Error

c# - 如何使用 StringFormat 舍入绑定(bind)的 double 值

wpf - 使用 Caliburn Micro 约定将 ViewModel 本身绑定(bind)到 DataTemplate 内

c# - 为 C++ 类的复杂系统创建 C# 绑定(bind)?

c# - Linq 隐式类型范围变量

c# - 解密一个用私钥签名的 byte[]

c# - 我们可以在c#中的datatable.select中添加参数吗