CalendarDatePicker öğesinden devralınan bir sınıf oluşturun, özel min/maks bağımlılık ekleyin.
public class CustomCalendarDatePicker : CalendarDatePicker
{
public DateTimeOffset Max
{
get { return (DateTimeOffset)GetValue(MaxProperty); }
set { SetValue(MaxProperty, value); }
}
public static readonly DependencyProperty MaxProperty =
DependencyProperty.Register(
nameof(Max), // The name of the DependencyProperty
typeof(DateTimeOffset), // The type of the DependencyProperty
typeof(CustomCalendarDatePicker), // The type of the owner of the DependencyProperty
new PropertyMetadata(
null, onMaxChanged // The default value of the DependencyProperty
));
private static void onMaxChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var calendar = d as CustomCalendarDatePicker;
calendar.MaxDate = (DateTimeOffset)e.NewValue;
}
public DateTimeOffset Min
{
get { return (DateTimeOffset)GetValue(MinProperty); }
set { SetValue(MinProperty, value); }
}
public static readonly DependencyProperty MinProperty =
DependencyProperty.Register(
nameof(Min), // The name of the DependencyProperty
typeof(DateTimeOffset), // The type of the DependencyProperty
typeof(CustomCalendarDatePicker), // The type of the owner of the DependencyProperty
new PropertyMetadata(
null, onMinChanged // The default value of the DependencyProperty
));
private static void onMinChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var calendar = d as CustomCalendarDatePicker;
calendar.MinDate = (DateTimeOffset)e.NewValue;
}
}
Kullanımı:
<controls:CustomCalendarDatePicker Min="" Max=""/>
Merhaba, teşekkürler cevap. Ben aynı denedim ama aşağıdaki hata alıyorum "10/2/2017" metin değeri, DateTimeOfffset türüne Min. xaml - local: CustomCalendarDatePicker> –
Min ve Max özellik türünü değiştirdim. DateTimeOffset dizgiye .şimdi çalışma teşekkürler –
Sizin için çalıştığıma memnun oldum, lütfen yanıt olarak kabul edin lütfen :) – thang2410199