Skip to content

Commit

Permalink
NavView: Fix CornerRadius for overflow menu and NavViewItem children …
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Nov 8, 2020
1 parent 7643681 commit 8198231
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
13 changes: 13 additions & 0 deletions test/ModernWpfTestApp/Utilities/VisualTreeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,18 @@ public static FrameworkElement FindVisualChildByName(this DependencyObject eleme

return null;
}

public static T FindVisualParentByType<T>(this DependencyObject element)
where T : DependencyObject
{
if (element is null)
{
return null;
}

return element is T elementAsT
? elementAsT
: VisualTreeHelper.GetParent(element).FindVisualParentByType<T>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@
<TextBlock Grid.Column="3" x:Name="TextblockCollapsedItemAndContainerMatch" AutomationProperties.Name="TextblockCollapsedItemAndContainerMatch" Text="N/A"/>
</Grid>
</StackPanel>

<!-- NavigationViewItem children flyout corner radius test components -->
<StackPanel Margin="0,10,0,10">
<StackPanel Orientation="Horizontal">
<Button x:Name="GetMenuItem1ChildrenFlyoutCornerRadiusButton" AutomationProperties.Name="GetMenuItem1ChildrenFlyoutCornerRadiusButton" Content="GetMenuItem1ChildrenFlyoutCornerRadius"
Click="GetMenuItem1ChildrenFlyoutCornerRadiusButton_Click"/>
<TextBlock Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center">CornerRadius:</TextBlock>
<TextBlock x:Name="MenuItem1ChildrenFlyoutCornerRadiusTextBlock" AutomationProperties.Name="MenuItem1ChildrenFlyoutCornerRadiusTextBlock" HorizontalAlignment="Center" VerticalAlignment="Center">-</TextBlock>
</StackPanel>
</StackPanel>

<!-- Combobox used to switch pane display modes -->
<ComboBoxEx x:Name="PaneDisplayModeCombobox"
AutomationProperties.Name="PaneDisplayModeCombobox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ModernWpf.Controls;

using NavigationViewItemInvokedEventArgs = ModernWpf.Controls.NavigationViewItemInvokedEventArgs;
using NavigationViewItem = ModernWpf.Controls.NavigationViewItem;
using NavigationViewItemExpandingEventArgs = ModernWpf.Controls.NavigationViewItemExpandingEventArgs;
using NavigationViewItemCollapsedEventArgs = ModernWpf.Controls.NavigationViewItemCollapsedEventArgs;
using NavigationViewPaneDisplayMode = ModernWpf.Controls.NavigationViewPaneDisplayMode;
using MUXControlsTestApp.Utilities;

namespace MUXControlsTestApp
{
Expand Down Expand Up @@ -122,5 +124,15 @@ private void PaneDisplayModeCombobox_SelectionChanged(object sender, SelectionCh
var mode = (NavigationViewPaneDisplayMode)Enum.Parse(typeof(NavigationViewPaneDisplayMode), tag);
navview.PaneDisplayMode = mode;
}

private void GetMenuItem1ChildrenFlyoutCornerRadiusButton_Click(object sender, RoutedEventArgs e)
{
var parent = MI2.FindVisualParentByType<FlyoutPresenter>();
if (parent is FlyoutPresenter flyoutPresenter)
{
var border = flyoutPresenter.FindVisualChildByType<Border>();
MenuItem1ChildrenFlyoutCornerRadiusTextBlock.Text = border?.CornerRadius.ToString() ?? "Internal Border not found";
}
}
}
}
11 changes: 9 additions & 2 deletions test/NavigationView_TestUI/TopMode/NavigationViewTopNavPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
mc:Ignorable="d"
Loaded="TestPage_Loaded">

<Page.Resources>
<local:TestPage.Resources>
<Style x:Key="AlternateToggleButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
<Setter Property="Content" Value="yo"/>
<Setter Property="Background" Value="Chartreuse"/>
</Style>
</Page.Resources>
</local:TestPage.Resources>

<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -202,6 +202,13 @@
<TextBlock x:Name="PaneOpenedOrClosedEvent" AutomationProperties.Name="PaneOpenedOrClosedEvent" Text="Unknown" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<Button x:Name="GetOverflowMenuCornerRadiusButton" AutomationProperties.Name="GetOverflowMenuCornerRadiusButton" Content="GetOverflowMenuCornerRadius"
Margin="0,0,2,0" Click="GetOverflowMenuCornerRadiusButton_Click"/>
<TextBlock Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center">CornerRadius:</TextBlock>
<TextBlock x:Name="OverflowMenuCornerRadiusTextBlock" AutomationProperties.Name="OverflowMenuCornerRadiusTextBlock" HorizontalAlignment="Center" VerticalAlignment="Center">-</TextBlock>
</StackPanel>

<TextBlock TextWrapping="Wrap" Grid.Row="1" Margin="5">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris faucibus quam id sem porta posuere. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi sodales suscipit justo quis consequat. Vestibulum lectus magna, mattis id eleifend sed, congue eget lectus. Nam et sem pellentesque, dignissim erat eu, tincidunt lacus. Ut porttitor tincidunt ullamcorper. Vestibulum sodales neque purus, vitae eleifend metus convallis in. Etiam non metus nec ligula pharetra molestie. Donec dignissim dapibus blandit. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,5 +516,16 @@ private void ClearSelectedItem_Click(object sender, RoutedEventArgs e)
{
NavView.SelectedItem = null;
}

private void GetOverflowMenuCornerRadiusButton_Click(object sender, RoutedEventArgs e)
{
var lastMenuItem = NavView.MenuItems[NavView.MenuItems.Count - 1] as NavigationViewItem;
var parent = lastMenuItem.FindVisualParentByType<FlyoutPresenter>();
if (parent is FlyoutPresenter flyoutPresenter)
{
var border = flyoutPresenter.FindVisualChildByType<Border>();
OverflowMenuCornerRadiusTextBlock.Text = border?.CornerRadius.ToString() ?? "Internal Border not found";
}
}
}
}

0 comments on commit 8198231

Please sign in to comment.