-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
I have a couple of TextBoxes within a Popup, which in turn resides in a custom control on my view. The TextBoxes are bound to VM properties - one int and one string. The binding on both TextBoxes use UpdateSourceTrigger=LostFocus. The Popup is opened via a button click (sets IsOpen = true).
If I open the popup, enter an invalid value into the int TextBox (e.g. "abc"), then tab to the second TextBox, the default MahApps validation error template appears as expected: a red border with a triangle in the top-right corner. If I tab back to the TextBox that is in error, an additional red "tooltip" appears to the right ("Value 'abc' could not be converted"), also as expected. However as soon as I type any character, valid or not (e.g. '1'), the following exception is thrown:-
System.InvalidOperationException
HResult=0x80131509
Message=The specified Visual is not an ancestor of this Visual.
Source=PresentationCore
StackTrace:
at System.Windows.Media.Visual.TrySimpleTransformToAncestor(Visual ancestor, Boolean inverse, GeneralTransform& generalTransform, Matrix& simpleTransform)
at System.Windows.Media.Visual.TransformToAncestor(Visual ancestor)
at MahApps.Metro.Controls.CustomValidationPopup.IsElementVisible(FrameworkElement element, FrameworkElement container)
at MahApps.Metro.Controls.CustomValidationPopup.ScrollViewer_ScrollChanged(Object sender, ScrollChangedEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.ScrollViewer.OnLayoutUpdated(Object sender, EventArgs e)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
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)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
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)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at *****.App.Main()
This exception was originally thrown at this call stack:
[External Code]
It's a complex app/UI so isn't something I can include here to demonstrate the issue. I did try reproducing it in a standalone app but it worked fine, so it seems there are other factors involved, and is not simply due to having TextBoxes inside a Popup.
MahApps.Metro version: v2.4.5
Windows build number: Win10 v 10.0.19042
Visual Studio: 2019 16.9.5
Target Framework: .Net Framework v4.6