Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update string reliance on WinUI NavigationView #4131

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public partial class ListDetailsView : ItemsControl
private ContentPresenter _detailsPresenter;
private VisualStateGroup _selectionStateGroup;
private Button _inlineBackButton;
private object _navigationView;
private Microsoft.UI.Xaml.Controls.NavigationView _navigationView;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a using at the top as well so we don't have to copy the namespace around:

using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView;

private Frame _frame;

/// <summary>
Expand Down Expand Up @@ -199,7 +199,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
_frame.Navigating -= OnFrameNavigating;
}

_navigationView = this.FindAscendants().FirstOrDefault(p => p.GetType().FullName == "Microsoft.UI.Xaml.Controls.NavigationView");
_navigationView = this.FindAscendant<Microsoft.UI.Xaml.Controls.NavigationView>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love seeing the new visual tree extensions being useful! 🙌

_frame = this.FindAscendant<Frame>();
if (_frame != null)
{
Expand Down Expand Up @@ -448,20 +448,11 @@ private void SetNavigationViewBackButtonState(int visible, bool enabled)
return;
}

var navType = _navigationView.GetType();
var visibleProperty = navType.GetProperty("IsBackButtonVisible");
if (visibleProperty != null)
{
_previousNavigationViewBackVisibilty = (int)visibleProperty.GetValue(_navigationView);
visibleProperty.SetValue(_navigationView, visible);
}
_previousNavigationViewBackVisibilty = (int)_navigationView.IsBackButtonVisible;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can strongly type to the enum value now over the int here too. 🙂

_navigationView.IsBackButtonVisible = (Microsoft.UI.Xaml.Controls.NavigationViewBackButtonVisible)visible;

var enabledProperty = navType.GetProperty("IsBackEnabled");
if (enabledProperty != null)
{
_previousNavigationViewBackEnabled = (bool)enabledProperty.GetValue(_navigationView);
enabledProperty.SetValue(_navigationView, enabled);
}
_previousNavigationViewBackEnabled = _navigationView.IsBackEnabled;
_navigationView.IsBackEnabled = enabled;
}

private void SetDetailsContent()
Expand Down