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
Show file tree
Hide file tree
Changes from all 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 @@ -74,19 +74,20 @@
</controls:ListDetailsView.NoSelectionContentTemplate>
<controls:ListDetailsView.ListCommandBar>
<CommandBar>
<!-- Button functionality to be implemented by developer -->
<AppBarButton Icon="Back" Label="Back"/>
<AppBarButton Icon="Forward" Label="Forward"/>

<CommandBar.Content>
<TextBlock Margin="12,14">
<Run Text="{Binding Emails.Count}" />
<Run Text="Items" />
</TextBlock>
</CommandBar.Content>
</CommandBar>
<CommandBar.Content>
<TextBlock Margin="12,14">
<Run Text="{Binding Emails.Count}" />
<Run Text="Items" />
</TextBlock>
</CommandBar.Content>
</CommandBar>
</controls:ListDetailsView.ListCommandBar>
<controls:ListDetailsView.DetailsCommandBar>
<CommandBar>
<!-- Button functionality to be implemented by developer -->
<AppBarButton Icon="MailReply" Label="Reply" />
<AppBarButton Icon="MailReplyAll" Label="Reply All" />
<AppBarButton Icon="MailForward" Label="Forward" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using NavigationView = Microsoft.UI.Xaml.Controls;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
Expand Down Expand Up @@ -42,12 +43,11 @@ public partial class ListDetailsView : ItemsControl
private AppViewBackButtonVisibility? _previousSystemBackButtonVisibility;
private bool _previousNavigationViewBackEnabled;

// Int used because the underlying type is an enum, but we don't have access to the enum
private int _previousNavigationViewBackVisibilty;
private NavigationView.NavigationViewBackButtonVisible _previousNavigationViewBackVisibilty;
private NavigationView.NavigationView _navigationView;
private ContentPresenter _detailsPresenter;
private VisualStateGroup _selectionStateGroup;
private Button _inlineBackButton;
private object _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<NavigationView.NavigationView>();
_frame = this.FindAscendant<Frame>();
if (_frame != null)
{
Expand Down Expand Up @@ -328,8 +328,6 @@ private void UpdateView(bool animate)
/// </summary>
private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
{
const int backButtonVisible = 1;

if (DesignMode.DesignModeEnabled)
{
return;
Expand Down Expand Up @@ -358,7 +356,7 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
}
else
{
SetNavigationViewBackButtonState(backButtonVisible, true);
SetNavigationViewBackButtonState(NavigationView.NavigationViewBackButtonVisible.Visible, true);
}
}
else if (BackButtonBehavior != BackButtonBehavior.Manual)
Expand Down Expand Up @@ -441,27 +439,18 @@ private void SetVisualState(bool animate)
VisualStateManager.GoToState(this, SelectedItem == null ? noSelectionState : hasSelectionState, animate);
}

private void SetNavigationViewBackButtonState(int visible, bool enabled)
private void SetNavigationViewBackButtonState(NavigationView.NavigationViewBackButtonVisible visibility, bool enabled)
{
if (_navigationView == null)
{
return;
}

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

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