WPF中DatePiker值绑定以及精简查询
阅读原文时间:2023年07月08日阅读:2

WPF中DatePiker值绑定以及精简查询

1.WPF中DatePiker值绑定

Xaml中值绑定使用Text

在ViewModel中使用strMinDate 转为DateTime.如下:

public string strMinDate
{
get { return this.GetProperty(() => strMinDate); }
set { this.SetProperty(() => strMinDate, value);
MinDateTime = Convert.ToDateTime(value);
}
}

public string strMaxDate
{
get { return this.GetProperty(() => strMaxDate); }
set { this.SetProperty(() => strMaxDate, value);
MaxDateTime = Convert.ToDateTime(value);
}
}

private DateTime? _minDateTime;
///

/// 起始时间 ///
public DateTime? MinDateTime
{
get { return _minDateTime; }
set
{
_minDateTime = value;
this.RaisePropertyChanged(() => MinDateTime);
}
}
private DateTime? _maxDateTime;
/// /// 结束时间 ///
public DateTime? MaxDateTime
{
get { return _maxDateTime; }
set
{
_maxDateTime = value;
this.RaisePropertyChanged(() => MaxDateTime);
}
}

2. Linq精简查询

public void Search()
{
DateTime tMin = _minDateTime == null ? DateTime.MinValue : _minDateTime.Value.Date;
DateTime tMax = _maxDateTime == null ? DateTime.MaxValue : _maxDateTime.Value.Date.AddDays(1);
IQueryable IResults = _databaseContext.SampleResults.Where(x => x.Sample.ArriveDateTime < tMax && x.Sample.ArriveDateTime >= tMin && x.Sample.Barcode.Contains(Barcode)).Include(p=>p.Sample).Include(p=>p.Sample.Test).Include(p=>p.Sample.Patient);
this.Results = new ObservableCollection(IResults);
}

3. 原代码:

Xaml:

1 10 11 12 13 14 15 16 17

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章