来自第二个分类的新属性不绑定

时间:2017-08-29 09:20:25

标签: c# wpf entity-framework xaml

我有来自EntityFramework Called Weights的部分课程

 public partial class Weights
{
    public long WeightID { get; set; }
    public Nullable<long> ClientID { get; set; }
    public Nullable<long> SiteID { get; set; }
    public Nullable<long> DriverID { get; set; }
    public Nullable<long> CarID { get; set; }
    public Nullable<double> Weight1 { get; set; }
    public Nullable<double> Weight2 { get; set; }
    public bool IsCancel { get; set; }
    public bool IsEdit { get; set; }
    public bool IsManual { get; set; }
    public Nullable<System.DateTime> DateTime1 { get; set; }
    public Nullable<System.DateTime> DateTime2 { get; set; }
    public Nullable<long> MaterialID { get; set; }
    public bool IsClosed { get; set; }
    public string Waybill { get; set; }
    public Nullable<double> Netto { get; set; }
    public Nullable<bool> Passage { get; set; }

    public virtual Cars Cars { get; set; }
    public virtual Clients Clients { get; set; }
    public virtual Drivers Drivers { get; set; }
    public virtual Materials Materials { get; set; }
    public virtual Sites Sites { get; set; }
}

现在我创建了另一个部分权重类,我实现了INotifyPropertyChanged并将datetimefrom和datetime添加到属性更改的属性

public partial class Weights : INotifyPropertyChanged
{
    private Nullable<System.DateTime> DateTimeFrom;
    public Nullable<System.DateTime> L_DateTimeFrom
    {
        get { return DateTimeFrom; }
        set
        {
            DateTimeFrom = value;
            NotifyPropertyChanged("DateTimeFrom");
        }
    }

    private Nullable<System.DateTime> DateTimeTo;
    public Nullable<System.DateTime> L_DateTimeTo
    {
        get { return DateTimeTo; }
        set
        {
            DateTimeTo = value;
            NotifyPropertyChanged("DateTimeTo");
        }
    }

    #region "PropertyEvent Change"
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
    #endregion
}

我创建了一个带有Weight Filter属性的viewmodel也实现了INotifyPropertyChanged

public class ClosedWeightsViewModel : INotifyPropertyChanged
{
    private Weights m_filter;
    public Weights Filter
    {
        get { return m_filter; }
        set
        {
            m_filter = value;
            NotifyPropertyChanged("Filter");
        }
    }

    #region "PropertyEvent Change"
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
    #endregion

}

在xaml中我创建了2个日期选择器并将它们绑定到datetimefrom / to

<StackPanel Orientation="Vertical" VerticalAlignment="Bottom">
                <DatePicker x:Name="dateForm" SelectedDate="{Binding Filter.DateTimeFrom, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" SelectedDateChanged="DatePicker_SelectedDateChanged"/>
                <DatePicker x:Name="dateTo" SelectedDate="{Binding Filter.DateTimeTo, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" SelectedDateChanged="DatePicker_SelectedDateChanged"/>
            </StackPanel>   

但是当我选择约会时,它并没有约束力。 其他属性的绑定工作得很好(CarID,DriverID等)

我缺少什么?

1 个答案:

答案 0 :(得分:0)

您的媒体资源名为L_DateTimeFromL_DateTimeTo。你应该重命名它们:

private Nullable<System.DateTime> _dateTimeFrom;
public Nullable<System.DateTime> DateTimeFrom
{
    get { return _dateTimeFrom; }
    set
    {
        _dateTimeFrom = value;
        NotifyPropertyChanged("DateTimeFrom");
    }
}

private Nullable<System.DateTime> _dateTimeTo;
public Nullable<System.DateTime> DateTimeTo
{
    get { return _dateTimeTo; }
    set
    {
        _dateTimeTo = value;
        NotifyPropertyChanged("DateTimeTo");
    }
}