wpf calendar

<Calendar SelectionMode="SingleRange"
                 Name="MonthlyCalendar"
                 SelectedDatesChanged="MonthlyCalendar_SelectedDatesChanged"
                 DisplayDateChanged="MonthlyCalendar_DisplayDateChanged"
                 DisplayModeChanged="MonthlyCalendar_DisplayModeChanged"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top"
                 Margin="10,10,0,0">           
</Calendar>
The code behind for these events looks like Listing 4.
private void MonthlyCalendar_SelectedDatesChanged(object sender,
    SelectionChangedEventArgs e)
{
}
 
private void MonthlyCalendar_DisplayDateChanged(object sender,
    CalendarDateChangedEventArgs e)
{
 
}
 
private void MonthlyCalendar_DisplayModeChanged(object sender,
    CalendarModeChangedEventArgs e)
{
 
}

Calendar Events

Besides the normal control events, the Calendar control has three events calendar related events. These events are the DisplayDateChanged, DisplayModeChanged, and SelectedDatesChanged. The DisplayDateChanged event is fired where the DisplayDate property is changed. The DisplayModeChanged event is fired when the DisplayMode property is changed. The SelectedDatesChanged event is fired when the SelectedDate or SelectedDates properties are changed. The following code snippet sets these three events attributes.


Listing 4

Normally, on a date selection, you may want to capture that event and know what the current selected date is. Now how about we add a TextBox control to the page and on the date selection, we are going to set the text of the TextBox to the currently selected date.

We add the following code to the XAML just below the Calendar control.

<TextBox Width="200" Height="30"
         VerticalAlignment="Bottom"
         HorizontalAlignment="Left"
         Margin="10,10,10,10"
         x:Name="SelectedDateTextBox">
   
</TextBox>
On the SelectedDateChanged event handler, we set the TextBox.Text property to the SelectedDate property of the Calendar control as you can see from code in Listing 5.
private void MonthlyCalendar_SelectedDatesChanged(object sender,
    SelectionChangedEventArgs e)
{
    SelectedDateTextBox.Text = MonthlyCalendar.SelectedDate.ToString();
}


Listing 5

Now when you run the application, you will see output looks like Figure 10. When you select a date in the Calendar, it will be displayed in the Textbox.

WPFCalImg10.jpg

Figure 10

http://www.c-sharpcorner.com/uploadfile/mahesh/wpf-calendar-control/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值