2021-08-14 WPF控件专题 Calendar 控件详解
Posted 微软MVP Eleven
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-08-14 WPF控件专题 Calendar 控件详解相关的知识,希望对你有一定的参考价值。
1.Calendar 控件介绍
可视化的日历控件 月历显示来选择日期
2.具体案例
<Grid>
<!--DisplayMode 默认Month SelectionMode 默认SingleDate-->
<Calendar Name="calDate" HorizontalAlignment="Left" Margin="117,124,0,0" VerticalAlignment="Top" Height="166" Width="190" DisplayMode="Month" DisplayDateStart="2020-5-1" DisplayDateEnd="2020-6-10" IsTodayHighlighted="True" SelectionMode="MultipleRange" IsTabStop="False" PreviewMouseUp="CalDate_PreviewMouseUp" />
<TextBox Name="txtStart" HorizontalAlignment="Left" Height="23" Margin="176,65,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox Name="txtEnd" HorizontalAlignment="Left" Height="23" Margin="340,65,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox Name="txtSel" HorizontalAlignment="Left" Height="23" Margin="24,65,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="349,155,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
private void Calendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
txtStart.Text = calDate.SelectedDates.First().ToShortDateString();
txtEnd.Text = calDate.SelectedDates.Last().ToShortDateString();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
txtSel.Text = calDate.SelectedDate.Value.ToShortDateString();
}
private void CalDate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (Mouse.Captured is CalendarItem)
{
Mouse.Capture(null);
}
}
以上是关于2021-08-14 WPF控件专题 Calendar 控件详解的主要内容,如果未能解决你的问题,请参考以下文章
2021-08-14 WPF控件专题 ProgressBar控件详解
2021-08-14 WPF控件专题 DatePicker 控件详解
2021-08-14 WPF控件专题 ListBox控件详解
2021-08-13 WPF控件专题 ComboBox 控件详解