728x90
기간으로 표시하기위한 Converter 추가
DateToDaysConverter.cs
using System;
using System.Globalization;
using System.Windows.Data;
namespace Wpf.DevGridTest
{
internal class DateToDaysConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (System.Convert.ToDateTime(value) - DateTime.Now).Days;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Resource 에 Converter 정의 및 DateEdit 에 적용
MainWindow.xaml
xmlns:local="clr-namespace:Wpf.DevGridTest"
<Window.Resources>
<local:DateToDaysConverter x:Key="DateToDaysConverter" />
</Window.Resources>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<dxe:DateEdit
Width="90"
Height="30"
VerticalAlignment="Center"
HorizontalContentAlignment="Right"
DisplayTextConverter="{StaticResource DateToDaysConverter}"
EditValue="{Binding FromDate}" />
<Label
VerticalAlignment="Center"
HorizontalContentAlignment="Right"
Content="~" />
<dxe:DateEdit
Width="90"
Height="30"
VerticalAlignment="Center"
HorizontalContentAlignment="Right"
DisplayTextConverter="{StaticResource DateToDaysConverter}"
EditValue="{Binding ToDate}" />
</StackPanel>
MainViewModel.cs
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
namespace Wpf.DevGridTest
{
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string name = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
private DateTime fromDate;
public DateTime FromDate
{
get => this.fromDate;
set
{
this.fromDate = value;
OnPropertyChanged();
}
}
private DateTime toDate;
public DateTime ToDate
{
get => this.toDate;
set
{
this.toDate = value;
OnPropertyChanged();
}
}
public MainViewModel()
{
FromDate = DateTime.Now.AddDays(-10);
ToDate = DateTime.Now;
}
}
}
결과
728x90
'DevExpress' 카테고리의 다른 글
[DevExpress/WPF] GridControl ReadOnly 처리하기 (0) | 2022.09.15 |
---|---|
[DevExpress/WPF] GridControl 에 ExpandObject 바인딩 하기 (0) | 2022.09.15 |
[DevExpress/WPF] TrackBarEdit - Background/SelectionColor (0) | 2022.08.30 |
[DevExpress/WPF] TrackBarEdit 소숫점처리 (0) | 2022.08.30 |
[DevExpress/WPF] TrackBarEdit 사용하기 - Dual(Range) Slider (0) | 2022.08.30 |