Skip to content

Commit

Permalink
Merge branch 'hotfix/2.4.6' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Jun 10, 2021
2 parents 4025dca + 39ba5fa commit 4421322
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
Style="{DynamicResource MahApps.Styles.TextBox.Button}" />
<TextBox Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.Watermark="Number smaller than 10"
Text="{Binding IntegerGreater10Property, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" />
Text="{Binding IntegerGreater10Property, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" />
<TextBox Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.SelectAllOnFocus="True"
Text="Select all on focus" />
Expand Down
6 changes: 3 additions & 3 deletions src/MahApps.Metro/Controls/CustomValidationPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e)
this.scrollViewer.ScrollChanged -= this.ScrollViewer_ScrollChanged;
}

this.scrollViewer = adornedElement.TryFindParent<ScrollViewer>();
this.scrollViewer = adornedElement.GetVisualAncestor<ScrollViewer>();
if (this.scrollViewer != null)
{
this.scrollViewer.ScrollChanged += this.ScrollViewer_ScrollChanged;
Expand Down Expand Up @@ -260,10 +260,10 @@ private void OnTransitionCompleted(object sender, RoutedEventArgs e)

private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
this.RefreshPosition();

if (e.VerticalChange > 0 || e.VerticalChange < 0 || e.HorizontalChange > 0 || e.HorizontalChange < 0)
{
this.RefreshPosition();

if (IsElementVisible(this.AdornedElement as FrameworkElement, this.scrollViewer))
{
var adornedElement = this.AdornedElement;
Expand Down
41 changes: 41 additions & 0 deletions src/MahApps.Metro/Controls/TreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,47 @@ public static IEnumerable<DependencyObject> GetAncestors(this DependencyObject c
}
}

/// <summary>
/// Returns full visual ancestry, starting at the leaf.
/// <para>If element is not of <see cref="Visual"/> or <see cref="Visual3D"/> the logical ancestry is used.</para>
/// </summary>
/// <param name="leaf">The starting object.</param>
/// <returns></returns>
public static IEnumerable<DependencyObject> GetVisualAncestry(this DependencyObject? leaf)
{
while (leaf != null)
{
yield return leaf;
leaf = leaf is Visual || leaf is Visual3D
? VisualTreeHelper.GetParent(leaf)
: LogicalTreeHelper.GetParent(leaf);
}
}

/// <summary>
/// Tries to find and returns a visual ancestor, starting at the leaf.
/// <para>If element is not of <see cref="Visual"/> or <see cref="Visual3D"/> the logical ancestry is used.</para>
/// </summary>
/// <param name="leaf">The starting object.</param>
/// <returns></returns>
public static T GetVisualAncestor<T>(this DependencyObject? leaf)
where T : DependencyObject
{
while (leaf != null)
{
if (leaf is T ancestor)
{
return ancestor;
}

leaf = leaf is Visual || leaf is Visual3D
? VisualTreeHelper.GetParent(leaf)
: LogicalTreeHelper.GetParent(leaf);
}

return default(T);
}

/// <summary>
/// Finds a Child of a given item in the visual tree.
/// </summary>
Expand Down

0 comments on commit 4421322

Please sign in to comment.