Changing the month of a DatePicker throws this exception:
System.Windows.Automation.ElementNotAvailableException: 'Element does not exist or it is virtualized; use VirtualizedItem Pattern if it is supported.'
The Stack Trace:
at MS.Internal.Automation.ElementUtil.Invoke(AutomationPeer peer, DispatcherOperationCallback work, Object arg) at MS.Internal.Automation.ElementProxy.GetPropertyValue(Int32 property)
I created a simple project with only one DatePicker on the main window and it gives the same exception.
<DatePicker x:Name="datePicker1" Width="150" />
.NET Framework version: 4.6
I found the same problem in a 6 years old question, but no answer till now!
Edit:
I tried different .NET Framework versions: 4.5, 4.6.1, and the problem still the same.
The exception appears to depend on the Tablet PC Input Service being enabled. If I had to guess, the error occurs in UI Automation code that only runs when pen-based input is available (and possibly touch-based input). I've seen that service induce undesirable side effects in WPF applications before, and most of those issues were also related to UI Automation.
Since this appears to be a "first chance" exception (it gets handled somewhere in the framework), the only people who should notice are developers who have their IDE configured to break on all exceptions (as opposed to only unhandled exceptions). If that is indeed the case, and if those developers are not actually using the pen or touch input capabilities, it might be easiest to just disable the Tablet PC Input Service and move on with your lives.
Alternatively, you could configure Visual Studio to not break on that particular exception type, which only pertains to UI Automation anyway.
Since things are pretty slow at the office this week, I will spend some additional time looking into this. If I can find a code-based solution, I will update my answer here. But from the look of it, the UI is constructed almost entirely programmatically, so this probably isn't something you can fix with a simple custom template.
If you look on the microsoft documentation it says:
This exception can be raised if the element was in a dialog box that was closed, or an application that was closed or terminated.
Could it be possible that you're closing the window on a "change month" event?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With