WPF DatePicker在更改月份时抛出异常

Rob*_*bin 6 c# wpf datepicker

好的我有这个项目我在WPF(Visual C#2010 Express)上工作,我有几个DatePickers绑定到DateTime属性.现在如果我打开"选择器"并立即开始更换几个月就没有问题了.但是,如果我选择日期然后尝试更改月份,则会出现以下异常:

元素不存在或虚拟化; 如果支持,请使用VirtualizedItem Pattern.

堆栈跟踪仅显示:

[外部代码]
我的方法打开包含DatePickers的对话框(除其他外)
[外部代码]

如果属性可以为空或者似乎没有区别,并且无法在上述异常的任何主要搜索引擎上找到单个结果.

XAML

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <DatePicker SelectedDate="{Binding TheDate}" 
                    x:Name="datePicker1" />
        <Button Content="Button"
                x:Name="button1" 
                Click="button1_Click" />
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

代码背后

    class TheClass
    {
        public DateTime TheDate { get; set; }
    }

    public MainWindow()
    {
        theClass = new TheClass();
        theClass.TheDate = DateTime.Now;

        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = theClass;
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        System.Windows.MessageBox.Show(theClass.TheDate.ToString());
    }
Run Code Online (Sandbox Code Playgroud)

有没有人见过这种行为或有任何其他想法?我离WPF专家很远,老实说不知道是什么导致这个或从哪里开始寻找..

She*_*byZ 0

我希望这可以是评论而不是答案,但这里是:

http://www.switchonthecode.com/tutorials/wpf-snippet-detecting-binding-errors

仔细阅读一下,如果您的情况存在问题,它应该会报告任何绑定错误。