From 4ca6e2b7691a96e1fae2346ce6cfba33d9ba4d04 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Tue, 19 May 2015 13:06:25 +0200 Subject: [PATCH] fix validation popup location flicker --- .../Controls/CustomValidationPopup.cs | 14 +++++-- .../Styles/ValidationErrorTemplate.xaml | 38 +++++++++++++++---- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/MahApps.Metro/Controls/CustomValidationPopup.cs b/MahApps.Metro/Controls/CustomValidationPopup.cs index e2164e3289..a7f0a690e5 100644 --- a/MahApps.Metro/Controls/CustomValidationPopup.cs +++ b/MahApps.Metro/Controls/CustomValidationPopup.cs @@ -104,6 +104,8 @@ private void hostWindow_StateChanged(object sender, EventArgs e) var holder = target != null ? target.DataContext as AdornedElementPlaceholder : null; if (holder != null && holder.AdornedElement != null) { + this.PopupAnimation = PopupAnimation.None; + this.IsOpen = false; var errorTemplate = holder.AdornedElement.GetValue(Validation.ErrorTemplateProperty); holder.AdornedElement.SetValue(Validation.ErrorTemplateProperty, null); holder.AdornedElement.SetValue(Validation.ErrorTemplateProperty, errorTemplate); @@ -153,9 +155,13 @@ private void SetTopmostState(bool isTop) } //Debug.WriteLine("setting z-order " + isTop); + var left = rect.left; + var top = rect.top; + var width = rect.Width; + var height = rect.Height; if (isTop) { - UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS); + UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOPMOST, left, top, width, height, Constants.TOPMOST_FLAGS); } else { @@ -163,9 +169,9 @@ private void SetTopmostState(bool isTop) // the titlebar (as opposed to other parts of the external // window) unless I first set the popup to HWND_BOTTOM // then HWND_TOP before HWND_NOTOPMOST - UnsafeNativeMethods.SetWindowPos(hwnd, HWND_BOTTOM, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS); - UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOP, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS); - UnsafeNativeMethods.SetWindowPos(hwnd, HWND_NOTOPMOST, rect.left, rect.top, (int)this.Width, (int)this.Height, Constants.TOPMOST_FLAGS); + UnsafeNativeMethods.SetWindowPos(hwnd, HWND_BOTTOM, left, top, width, height, Constants.TOPMOST_FLAGS); + UnsafeNativeMethods.SetWindowPos(hwnd, HWND_TOP, left, top, width, height, Constants.TOPMOST_FLAGS); + UnsafeNativeMethods.SetWindowPos(hwnd, HWND_NOTOPMOST, left, top, width, height, Constants.TOPMOST_FLAGS); } this.appliedTopMost = isTop; diff --git a/MahApps.Metro/Styles/ValidationErrorTemplate.xaml b/MahApps.Metro/Styles/ValidationErrorTemplate.xaml index 73ab38185b..27ac21304c 100644 --- a/MahApps.Metro/Styles/ValidationErrorTemplate.xaml +++ b/MahApps.Metro/Styles/ValidationErrorTemplate.xaml @@ -29,30 +29,37 @@ - - + PlacementTarget="{Binding ElementName=PopupTargetElement, Mode=OneWay}" + IsOpen="False"> +