简体   繁体   中英

Is there a way to stop the Calendar control going into Month view?

I need to add in a Calendar control that will let the user select which month of data they would like to view/export. But when I select a month in the Calendar control it automatically changes the Display Mode to the 'Month' view.

CalendarDisplayModeChange

I am new to C# and WPF so I feel like this should be a straight forward thing. I just don't know the proper syntax. That being said I have tried to turn off manipulation and I tried having the calendar view go back to a 'Year' view if it detects a Display Mode change.

Here is my current XAML code that builds the Calendar.

<Calendar Name="MonthCal" DisplayMode="Year" SelectionMode="MultipleRange"/>

I would expect the control to A) stay in the 'Year' view and B) provide the selected month information to my program. I could filter the month from the date but that just defeats the purpose of having the user select a month. I would be perfectly happy with a simple message box that said "User Selected X Month". I could take it from there as needed.

Monitor the event for DisplayModeChanged on the calendar item.

   private void MonthCal_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e)
    {
       if (!e.NewMode.Equals(CalendarMode.Year)) { MonthCal.DisplayMode = CalendarMode.Year; }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM