相关疑难解决方法(0)

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专家很远,老实说不知道是什么导致这个或从哪里开始寻找..

c# wpf datepicker

6
推荐指数
1
解决办法
1424
查看次数

元素不存在或被虚拟化;如果支持,请使用 VirtualizedItem 模式

我们有一个 WPF 应用程序。我们的一些客户发生了崩溃,我无法在我的机器上重现。我可以从他们的机器上获得的所有信息都低于堆栈跟踪,其中仅包含 WPF 代码,因此我实际上无法确定我的应用程序中的代码导致这个问题。

System.Windows.Automation.ElementNotAvailableException: Element does not exist or it is virtualized; use VirtualizedItem Pattern if it is supported.
at System.Windows.Automation.Peers.ItemAutomationPeer.ThrowElementNotAvailableException()
at System.Windows.Automation.Peers.ItemAutomationPeer.GetItemStatusCore()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
Run Code Online (Sandbox Code Playgroud)

有没有人面临同样的问题?任何帮助表示赞赏。这可能与 windows 10 有关,但我不确定,因为我的机器也是 windows 10,但我没有收到此错误。

.net c# windows wpf

4
推荐指数
1
解决办法
2212
查看次数

标签 统计

c# ×2

wpf ×2

.net ×1

datepicker ×1

windows ×1