WPF中的数据形式和第二级对象绑定

本文关键字:二级 绑定 对象 数据 WPF | 更新日期: 2023-09-27 18:12:59

我正在使用Telerik的WPF控件与Caliburn.Micro。特别是DataForm控件。我正在尝试将它绑定到一个具有以下组成的对象。

public class FrequencyMap : BindableBase
{
    private Guid id;
    public Guid ID
    {
        get { return id; }
        set
        {
            id = value;
            OnPropertyChanged();
        }
    }
    private string procedureCodeId;
    public string ProcedureCodeId
    {
        get { return procedureCodeId; }
        set
        {
            procedureCodeId = value;
            OnPropertyChanged();
        }
    }
    private FrequencyChoice frequency;
    public FrequencyChoice Frequency
    {
        get { return frequency; }
        set
        {
            frequency = value;
            OnPropertyChanged();
        }
    }
    private DateTime effectiveDate;
    public DateTime EffectiveDate
    {
        get { return effectiveDate; }
        set
        {
            effectiveDate = value;
            OnPropertyChanged();
        }
    }
    private DateTime? terminateDate;
    public DateTime? TerminateDate
    {
        get { return terminateDate; }
        set
        {
            terminateDate = value;
            OnPropertyChanged();
        }
    }
}

然后FrequencyChoice对象看起来像这样:

    public class FrequencyChoice : BindableBase
{
    private int id;
    private string modifiedUser;
    public int ID
    {
        get { return id; }
        set
        {
            id = value; OnPropertyChanged();
        }
    }
    private string code;
    public string Code
    {
        get { return code; }
        set
        {
            code = value; OnPropertyChanged();
        }
    }
    private string name;
    public string Name
    {
        get { return name; }
        set
        {
            name = value; OnPropertyChanged();
        }
    }
    private string description;
    public string Description
    {
        get { return description; }
        set
        {
            description = value; OnPropertyChanged();
        }
    }
    private string calculationDescription;
    public string CalculationDescription
    {
        get { return calculationDescription; }
        set
        {
            calculationDescription = value; OnPropertyChanged();
        }
    }
    private DateTime inactiveDate;
    public DateTime InactiveDate
    {
        get { return inactiveDate; }
        set
        {
            inactiveDate = value; OnPropertyChanged();
        }
    }
    public string ModifiedUser
    {
        get
        {
            return this.modifiedUser;
        }
        set
        {
            this.modifiedUser = value;
            OnPropertyChanged();
        }
    }
}

除了Frequency属性外,这工作得很好。我怎么才能让它正常工作。我必须像这篇文章一样使用Enum吗?XAML中的数据表单如果是这样,我该如何将两者联系起来?

WPF中的数据形式和第二级对象绑定

我猜你想要的是1频率图与许多频率选择的关系

首先我将改变属性从PropertyChangedBase

继承
 public class FrequencyChoice : PropertyChangedBase
 {
 }

然后更改属性,如下所示

 private BindableCollection<FrequencyChoice> frequencyChoices;
    public BindableCollection<FrequencyChoice> FrequencyChoices
    {
        get
        {
            return this.frequencyChoices;
        }
        set
        {
            if (Equals(value, this.frequencyChoices))
            {
                return;
            }
            this.frequencyChoices = value;
            this.NotifyOfPropertyChange(() => this.FrequencyChoices);
        }
    }

我不太确定什么是BindableBase(从谷歌是Prism,但他们使用的是Caliburn,所以使用PropertyChangedBase)但如果你想继续使用它,请继续使用,但要确保它为你处理更改通知

由于每个映射都有许多选择,因此需要集合来存储这些选择