WPF中的DataForm和第二级对象绑定

时间:2013-05-09 01:56:02

标签: c# wpf data-binding telerik caliburn.micro

我正在使用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吗? Data Forms in your XAML 如果是这样我将如何链接这两个?

1 个答案:

答案 0 :(得分:0)

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

第一,我会将属性更改为继承自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(来自google是Prism,但是你使用Caliburn所以使用PropertyChangedBase)但是如果想继续使用它继续但只是确保它处理你的更改通知

由于每个地图都有很多选择,因此您需要收集来存储选项