简体   繁体   English

有没有办法阻止日历控件进入月视图?

[英]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.我需要添加一个日历控件,让用户 select 他们想查看/导出哪个月份的数据。 But when I select a month in the Calendar control it automatically changes the Display Mode to the 'Month' view.但是当我在日历控件中一个月 select 时,它会自动将显示模式更改为“月”视图。

CalendarDisplayModeChange日历显示模式更改

I am new to C# and WPF so I feel like this should be a straight forward thing.我是 C# 和 WPF 的新手,所以我觉得这应该是直截了当的事情。 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.话虽如此,我已尝试关闭操作,并且如果检测到显示模式更改,我尝试将日历视图 go 返回到“年”视图。

Here is my current XAML code that builds the Calendar.这是我当前构建日历的 XAML 代码。

<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.我希望控件 A)停留在“年”视图中,B)向我的程序提供选定的月份信息。 I could filter the month from the date but that just defeats the purpose of having the user select a month.我可以从日期中过滤月份,但这违背了让用户 select 一个月的目的。 I would be perfectly happy with a simple message box that said "User Selected X Month".我会对一个简单的消息框感到非常满意,上面写着“用户选择 X 个月”。 I could take it from there as needed.我可以根据需要从那里拿走它。

Monitor the event for DisplayModeChanged on the calendar item.监视日历项上的 DisplayModeChanged 事件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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