如何在选定日期自动关闭 telerik RadDateTimePicker
How to auto-close a telerik RadDateTimePicker on selected date
控件声明如下:
<telerik:RadDateTimePicker InputMode="DateTimePicker"
IsTabStop="False"
Height="36"
Focusable="False"
Validation.ErrorTemplate="{x:Null}"
SelectionOnFocus="SelectAll"
x:Name="OutwardStartDate"
BorderThickness="2,2,2,2"
SelectedValue="{Binding OutwardDepartureDate, Mode=TwoWay, ValidatesOnDataErrors=true,
NotifyOnValidationError=true}" >
我找不到任何 XAML 属性来在选择日期时自动关闭此控件。我偶然发现了 this post on the official website,但是这个问题是 5 年前的,none 当前的答案解决了我的问题。
您可以简单地挂钩到 SelectionChanged 事件。
在你的XAML如下:
<telerik:RadDateTimePicker InputMode="DateTimePicker"
SelectionChanged="RadDateTimePicker_SelectionChanged"
IsTabStop="False"
Height="36"
Focusable="False"
Validation.ErrorTemplate="{x:Null}"
SelectionOnFocus="SelectAll"
x:Name="OutwardStartDate"
BorderThickness="2,2,2,2"
SelectedValue="{Binding OutwardDepartureDate,
Mode=TwoWay,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}">
并在后面的代码中更改 IsDropDownOpen 属性 :
private void RadDateTimePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems != null)
{
var dateTimePicker = sender as RadDateTimePicker;
dateTimePicker.IsDropDownOpen = false;
}
}
控件声明如下:
<telerik:RadDateTimePicker InputMode="DateTimePicker"
IsTabStop="False"
Height="36"
Focusable="False"
Validation.ErrorTemplate="{x:Null}"
SelectionOnFocus="SelectAll"
x:Name="OutwardStartDate"
BorderThickness="2,2,2,2"
SelectedValue="{Binding OutwardDepartureDate, Mode=TwoWay, ValidatesOnDataErrors=true,
NotifyOnValidationError=true}" >
我找不到任何 XAML 属性来在选择日期时自动关闭此控件。我偶然发现了 this post on the official website,但是这个问题是 5 年前的,none 当前的答案解决了我的问题。
您可以简单地挂钩到 SelectionChanged 事件。
在你的XAML如下:
<telerik:RadDateTimePicker InputMode="DateTimePicker"
SelectionChanged="RadDateTimePicker_SelectionChanged"
IsTabStop="False"
Height="36"
Focusable="False"
Validation.ErrorTemplate="{x:Null}"
SelectionOnFocus="SelectAll"
x:Name="OutwardStartDate"
BorderThickness="2,2,2,2"
SelectedValue="{Binding OutwardDepartureDate,
Mode=TwoWay,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}">
并在后面的代码中更改 IsDropDownOpen 属性 :
private void RadDateTimePicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems != null)
{
var dateTimePicker = sender as RadDateTimePicker;
dateTimePicker.IsDropDownOpen = false;
}
}