XAML中的代码隐藏中缺少参数 [英] Missing arguments in code-behind from XAML
问题描述
我有一个压光机控件,我想确保仅显示日历模式Month和Year.这是XAML:
<日历x:Name =" calMonth" Grid.Column ="1". HorizontalAlignment =左" VerticalAlignment =中心". DisplayDate ="{{Binding Month,Mode = TwoWay}"" 高度="30". 宽度="180". 保证金="3,0,0,0&"; IsTodayHighlighted =假". BorderThickness ="0". DisplayModeChanged ="calcalth_DisplayModeChanged"
在后面的代码中,我想限制为这两种模式:
私有无效的calMonth_DisplayModeChanged(对象发送者,CalendarModeChangedEventArgs e) { Calendar cal =发件人为Calendar; 如果(cal.DisplayMode == CalendarMode.Month) { cal.DisplayMode = CalendarMode.Year; } 别的 { cal.DisplayMode = CalendarMode.Month; } e.Handled = true; }
但是例程的执行导致"System.StackOverflowException",说明我有一个无限循环.在调试器中检查代码表明,从未达到e.Handled = true,因为显然每个 mode更改都会在触发该函数之前 整个功能已执行.
因此,我将e.Handled = true语句放在函数顶部,现在我收到"System.InvalidOperationException",声明必须为所有RoutedEventArgs分配一个非空的RoutedEvent.在调试器中展开e将显示RoutedEvent 属性值为null.
有任何提示吗?
没有时间尝试执行此操作,但是我将绑定DisplayMode,并且在setter中仅接受所需的值. /blockquote>
I have a calender control where I would like to make sure that only the calendar modes Month and Year will be displayed. This is the XAML:
<Calendar x:Name="calMonth" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" DisplayDate="{Binding Month,Mode=TwoWay}" Height="30" Width="180" Margin="3,0,0,0" IsTodayHighlighted="False" BorderThickness="0" DisplayModeChanged="calMonth_DisplayModeChanged">In the code-behind I want to restrict to those two modes:
private void calMonth_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e) { Calendar cal = sender as Calendar; if (cal.DisplayMode == CalendarMode.Month) { cal.DisplayMode = CalendarMode.Year; } else { cal.DisplayMode = CalendarMode.Month; } e.Handled = true; }But the routine execution leads to a 'System.StackOverflowException', stating that I have an endless loop. Checking the code in debugger shows that the e.Handled = true is never reached because obviously every mode change triggers the function before the entire function has been executed.
So I put the e.Handled = true statement to the top of the function and now I receive the 'System.InvalidOperationException' stating that to all RoutedEventArgs there must be a non-null RoutedEvent assigned to. Expanding e in Debugger shows a RoutedEvent property with value null.
Any hint?
解决方案Don't have time to try this but I would bind the DisplayMode and in the setter only accept the values you want.
这篇关于XAML中的代码隐藏中缺少参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!