Skip to content

Commit

Permalink
(MahAppsGH-3804, MahAppsGH-3809) Fix another wrong validation popup view
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed May 23, 2020
1 parent bed14f8 commit 35b44a1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/MahApps.Metro/Controls/CustomValidationPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)

private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e)
{
var canShow = true;

var adornedElement = this.AdornedElement;
if (adornedElement is null)
{
Expand All @@ -133,6 +131,9 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e)
return;
}

this.SetValue(CanShowPropertyKey, false);
var canShow = true;

if (this.scrollViewer != null)
{
this.scrollViewer.ScrollChanged -= this.ScrollViewer_ScrollChanged;
Expand All @@ -153,6 +154,7 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e)
this.metroContentControl = adornedElement.TryFindParent<MetroContentControl>();
if (this.metroContentControl != null)
{
canShow = !this.metroContentControl.TransitionsEnabled || !this.metroContentControl.IsTransitioning;
this.metroContentControl.TransitionStarted += this.OnTransitionStarted;
this.metroContentControl.TransitionCompleted += this.OnTransitionCompleted;
}
Expand All @@ -165,7 +167,7 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e)
this.transitioningContentControl = adornedElement.TryFindParent<TransitioningContentControl>();
if (this.transitioningContentControl != null)
{
canShow = !this.transitioningContentControl.IsTransitioning;
canShow = canShow && (this.transitioningContentControl.CurrentTransition == null || !this.transitioningContentControl.IsTransitioning);
this.transitioningContentControl.TransitionCompleted += this.OnTransitionCompleted;
}

Expand Down Expand Up @@ -202,12 +204,13 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e)
frameworkElement.SizeChanged += this.OnSizeOrLocationChanged;
}

this.RefreshPosition();
this.SetValue(CanShowPropertyKey, canShow);

this.OnLoaded();

this.Unloaded -= this.CustomValidationPopup_Unloaded;
this.Unloaded += this.CustomValidationPopup_Unloaded;

this.SetValue(CanShowPropertyKey, canShow);
}

private void Flyout_OpeningFinished(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -254,15 +257,18 @@ private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
this.RefreshPosition();

if (IsElementVisible(this.AdornedElement as FrameworkElement, this.scrollViewer))
if (e.VerticalChange > 0 || e.VerticalChange < 0 || e.HorizontalChange > 0 || e.HorizontalChange < 0)
{
var adornedElement = this.AdornedElement;
var isOpen = Validation.GetHasError(adornedElement) && adornedElement.IsKeyboardFocusWithin;
this.SetCurrentValue(IsOpenProperty, isOpen);
}
else
{
this.SetCurrentValue(IsOpenProperty, false);
if (IsElementVisible(this.AdornedElement as FrameworkElement, this.scrollViewer))
{
var adornedElement = this.AdornedElement;
var isOpen = Validation.GetHasError(adornedElement) && adornedElement.IsKeyboardFocusWithin;
this.SetCurrentValue(IsOpenProperty, isOpen);
}
else
{
this.SetCurrentValue(IsOpenProperty, false);
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/MahApps.Metro/Controls/MetroContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ public event RoutedEventHandler TransitionCompleted
remove => this.RemoveHandler(TransitionCompletedEvent, value);
}

/// <summary>Identifies the <see cref="IsTransitioning"/> dependency property.</summary>
public static readonly DependencyPropertyKey IsTransitioningPropertyKey
= DependencyProperty.RegisterReadOnly(nameof(IsTransitioning),
typeof(bool),
typeof(MetroContentControl),
new PropertyMetadata(default(bool)));

/// <summary>Identifies the <see cref="IsTransitioning"/> dependency property.</summary>
public static readonly DependencyProperty IsTransitioningProperty = IsTransitioningPropertyKey.DependencyProperty;

/// <summary>
/// Gets whether if the content is transitioning.
/// </summary>
public bool IsTransitioning
{
get => (bool)this.GetValue(IsTransitioningProperty);
protected set => this.SetValue(IsTransitioningPropertyKey, value);
}

public MetroContentControl()
{
this.DefaultStyleKey = typeof(MetroContentControl);
Expand Down Expand Up @@ -201,6 +220,7 @@ private void AfterLoadedStoryboardCurrentTimeInvalidated(object sender, System.E
{
if (clock.CurrentState == ClockState.Active)
{
this.SetValue(IsTransitioningPropertyKey, true);
this.RaiseEvent(new RoutedEventArgs(TransitionStartedEvent));
}
}
Expand All @@ -214,6 +234,7 @@ private void AfterLoadedStoryboardCompleted(object sender, System.EventArgs e)
}

this.InvalidateVisual();
this.SetValue(IsTransitioningPropertyKey, false);
this.RaiseEvent(new RoutedEventArgs(TransitionCompletedEvent));
}

Expand Down
2 changes: 1 addition & 1 deletion src/MahApps.Metro/Controls/TransitioningContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static void OnIsTransitioningPropertyChanged(DependencyObject d, Depende
}
}

private Storyboard CurrentTransition
internal Storyboard CurrentTransition
{
get { return this.currentTransition; }
set
Expand Down

0 comments on commit 35b44a1

Please sign in to comment.