Skip to content

Commit

Permalink
Merge pull request #4131 from XAML-Knight/ListDetailsView_RemoveHardc…
Browse files Browse the repository at this point in the history
…oded

Update string reliance on WinUI NavigationView
  • Loading branch information
XAML-Knight committed Jul 28, 2021
2 parents 8ecc496 + 2978876 commit cbefac4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
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

0 comments on commit cbefac4

Please sign in to comment.