|
10 | 10 | using Windows.UI.Xaml.Controls;
|
11 | 11 | using Windows.UI.Xaml.Input;
|
12 | 12 | using Windows.UI.Xaml.Navigation;
|
| 13 | +using NavigationView = Microsoft.UI.Xaml.Controls; |
13 | 14 |
|
14 | 15 | namespace Microsoft.Toolkit.Uwp.UI.Controls
|
15 | 16 | {
|
@@ -42,12 +43,11 @@ public partial class ListDetailsView : ItemsControl
|
42 | 43 | private AppViewBackButtonVisibility? _previousSystemBackButtonVisibility;
|
43 | 44 | private bool _previousNavigationViewBackEnabled;
|
44 | 45 |
|
45 |
| - // Int used because the underlying type is an enum, but we don't have access to the enum |
46 |
| - private int _previousNavigationViewBackVisibilty; |
| 46 | + private NavigationView.NavigationViewBackButtonVisible _previousNavigationViewBackVisibilty; |
| 47 | + private NavigationView.NavigationView _navigationView; |
47 | 48 | private ContentPresenter _detailsPresenter;
|
48 | 49 | private VisualStateGroup _selectionStateGroup;
|
49 | 50 | private Button _inlineBackButton;
|
50 |
| - private object _navigationView; |
51 | 51 | private Frame _frame;
|
52 | 52 |
|
53 | 53 | /// <summary>
|
@@ -199,7 +199,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
|
199 | 199 | _frame.Navigating -= OnFrameNavigating;
|
200 | 200 | }
|
201 | 201 |
|
202 |
| - _navigationView = this.FindAscendants().FirstOrDefault(p => p.GetType().FullName == "Microsoft.UI.Xaml.Controls.NavigationView"); |
| 202 | + _navigationView = this.FindAscendant<NavigationView.NavigationView>(); |
203 | 203 | _frame = this.FindAscendant<Frame>();
|
204 | 204 | if (_frame != null)
|
205 | 205 | {
|
@@ -328,8 +328,6 @@ private void UpdateView(bool animate)
|
328 | 328 | /// </summary>
|
329 | 329 | private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
|
330 | 330 | {
|
331 |
| - const int backButtonVisible = 1; |
332 |
| - |
333 | 331 | if (DesignMode.DesignModeEnabled)
|
334 | 332 | {
|
335 | 333 | return;
|
@@ -358,7 +356,7 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
|
358 | 356 | }
|
359 | 357 | else
|
360 | 358 | {
|
361 |
| - SetNavigationViewBackButtonState(backButtonVisible, true); |
| 359 | + SetNavigationViewBackButtonState(NavigationView.NavigationViewBackButtonVisible.Visible, true); |
362 | 360 | }
|
363 | 361 | }
|
364 | 362 | else if (BackButtonBehavior != BackButtonBehavior.Manual)
|
@@ -441,27 +439,18 @@ private void SetVisualState(bool animate)
|
441 | 439 | VisualStateManager.GoToState(this, SelectedItem == null ? noSelectionState : hasSelectionState, animate);
|
442 | 440 | }
|
443 | 441 |
|
444 |
| - private void SetNavigationViewBackButtonState(int visible, bool enabled) |
| 442 | + private void SetNavigationViewBackButtonState(NavigationView.NavigationViewBackButtonVisible visibility, bool enabled) |
445 | 443 | {
|
446 | 444 | if (_navigationView == null)
|
447 | 445 | {
|
448 | 446 | return;
|
449 | 447 | }
|
450 | 448 |
|
451 |
| - var navType = _navigationView.GetType(); |
452 |
| - var visibleProperty = navType.GetProperty("IsBackButtonVisible"); |
453 |
| - if (visibleProperty != null) |
454 |
| - { |
455 |
| - _previousNavigationViewBackVisibilty = (int)visibleProperty.GetValue(_navigationView); |
456 |
| - visibleProperty.SetValue(_navigationView, visible); |
457 |
| - } |
| 449 | + _previousNavigationViewBackVisibilty = _navigationView.IsBackButtonVisible; |
| 450 | + _navigationView.IsBackButtonVisible = visibility; |
458 | 451 |
|
459 |
| - var enabledProperty = navType.GetProperty("IsBackEnabled"); |
460 |
| - if (enabledProperty != null) |
461 |
| - { |
462 |
| - _previousNavigationViewBackEnabled = (bool)enabledProperty.GetValue(_navigationView); |
463 |
| - enabledProperty.SetValue(_navigationView, enabled); |
464 |
| - } |
| 452 | + _previousNavigationViewBackEnabled = _navigationView.IsBackEnabled; |
| 453 | + _navigationView.IsBackEnabled = enabled; |
465 | 454 | }
|
466 | 455 |
|
467 | 456 | private void SetDetailsContent()
|
|
0 commit comments