Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Fixed not showing chats on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Nov 8, 2019
1 parent 6891ae1 commit ed23b21
Showing 1 changed file with 45 additions and 44 deletions.
89 changes: 45 additions & 44 deletions UWPX_UI/Controls/Toolkit/MasterDetailsView/MasterDetailsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,29 @@ private static void OnMasterCommandBarChanged(DependencyObject d, DependencyProp

private void OnLoaded(object sender, RoutedEventArgs e)
{
if (DesignMode.DesignModeEnabled)
if (!DesignMode.DesignModeEnabled)
{
return;
}
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
if (_frame != null)
{
_frame.Navigating -= OnFrameNavigating;
}

SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
if (_frame != null)
{
_frame.Navigating -= OnFrameNavigating;
}
_navigationView = this.FindAscendants().FirstOrDefault(p => p.GetType().FullName == "Microsoft.UI.Xaml.Controls.NavigationView");
_frame = this.FindAscendant<Frame>();
if (_frame != null)
{
_frame.Navigating += OnFrameNavigating;
}

_navigationView = this.FindAscendants()?.FirstOrDefault(p => p.GetType().FullName == "Microsoft.UI.Xaml.Controls.NavigationView");
_frame = this.FindAscendant<Frame>();
if (_frame != null)
{
_frame.Navigating += OnFrameNavigating;
}
_selectionStateGroup = (VisualStateGroup)GetTemplateChild(SelectionStates);
if (_selectionStateGroup != null)
{
_selectionStateGroup.CurrentStateChanged += OnSelectionStateChanged;
}

_selectionStateGroup = (VisualStateGroup)GetTemplateChild(SelectionStates);
if (_selectionStateGroup != null)
{
_selectionStateGroup.CurrentStateChanged += OnSelectionStateChanged;
UpdateView(true);
}

UpdateView(true);
}

public void ClearSelectedItem()
Expand All @@ -232,22 +230,20 @@ public void ClearSelectedItem()

private void OnUnloaded(object sender, RoutedEventArgs e)
{
if (DesignMode.DesignModeEnabled)
{
return;
}

SystemNavigationManager.GetForCurrentView().BackRequested -= OnBackRequested;
if (_frame != null)
if (!DesignMode.DesignModeEnabled)
{
_frame.Navigating -= OnFrameNavigating;
}
SystemNavigationManager.GetForCurrentView().BackRequested -= OnBackRequested;
if (_frame != null)
{
_frame.Navigating -= OnFrameNavigating;
}

_selectionStateGroup = (VisualStateGroup)GetTemplateChild(SelectionStates);
if (_selectionStateGroup != null)
{
_selectionStateGroup.CurrentStateChanged -= OnSelectionStateChanged;
_selectionStateGroup = null;
_selectionStateGroup = (VisualStateGroup)GetTemplateChild(SelectionStates);
if (_selectionStateGroup != null)
{
_selectionStateGroup.CurrentStateChanged -= OnSelectionStateChanged;
_selectionStateGroup = null;
}
}
}

Expand Down Expand Up @@ -275,7 +271,7 @@ private void HandleStateChanges()
/// <summary>
/// Closes the details pane if we are in narrow state
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="sender">The sender</param>
/// <param name="args">The event args</param>
private void OnFrameNavigating(object sender, NavigatingCancelEventArgs args)
{
Expand All @@ -289,7 +285,7 @@ private void OnFrameNavigating(object sender, NavigatingCancelEventArgs args)
/// <summary>
/// Closes the details pane if we are in narrow state
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="sender">The sender</param>
/// <param name="args">The event args</param>
private void OnBackRequested(object sender, BackRequestedEventArgs args)
{
Expand Down Expand Up @@ -348,7 +344,7 @@ private void SetBackButtonVisibility(MasterDetailsViewState? previousState = nul
// Setting this indicates that the system back button is being used
_previousSystemBackButtonVisibility = navigationManager.AppViewBackButtonVisibility;
}
else if ((_navigationView == null) || (_frame == null))
else if ((_inlineBackButton != null) && ((_navigationView == null) || (_frame == null)))
{
// We can only use the new NavigationView if we also have a Frame
// If there is no frame we have to use the inline button
Expand All @@ -375,9 +371,9 @@ private void SetBackButtonVisibility(MasterDetailsViewState? previousState = nul
}
else if (BackButtonBehavior == BackButtonBehavior.Automatic)
{
if (!(_previousSystemBackButtonVisibility is null))
if (!_previousSystemBackButtonVisibility.HasValue)
{
if ((_navigationView == null) || (_frame == null))
if ((_inlineBackButton != null) && ((_navigationView == null) || (_frame == null)))
{
_inlineBackButton.Visibility = Visibility.Collapsed;
}
Expand Down Expand Up @@ -437,10 +433,16 @@ private void SetVisualState(bool animate)

VisualStateManager.GoToState(this, state, animate);
VisualStateManager.GoToState(this, SelectedItem == null ? noSelectionState : hasSelectionState, animate);
VisualStateManager.GoToState(this, Items.Count > 0 ? HasItemsState : HasNoItemsState, animate);
}

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

System.Type navType = _navigationView.GetType();
PropertyInfo visibleProperty = navType.GetProperty("IsBackButtonVisible");
if (visibleProperty != null)
Expand Down Expand Up @@ -479,8 +481,7 @@ private void OnDetailsCommandBarChanged()

private void OnCommandBarChanged(string panelName, CommandBar commandbar)
{
Panel panel = GetTemplateChild(panelName) as Panel;
if (panel == null)
if (!(GetTemplateChild(panelName) is Panel panel))
{
return;
}
Expand Down Expand Up @@ -513,7 +514,7 @@ private void SetListSelectionWithKeyboardFocusOnVisualStateChanged(MasterDetails
/// </summary>
private void SetListSelectionWithKeyboardFocus(bool singleSelectionFollowsFocus)
{
if (GetTemplateChild("MasterList") is Windows.UI.Xaml.Controls.ListViewBase masterList)
if (GetTemplateChild("MasterList") is ListViewBase masterList)
{
masterList.SingleSelectionFollowsFocus = singleSelectionFollowsFocus;
}
Expand All @@ -522,7 +523,7 @@ private void SetListSelectionWithKeyboardFocus(bool singleSelectionFollowsFocus)
/// <summary>
/// Fires when the selection state of the control changes
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="sender">the sender</param>
/// <param name="e">the event args</param>
/// <remarks>
/// Sets focus to the item list when the viewState is not Details.
Expand Down Expand Up @@ -573,4 +574,4 @@ private void FocusItemList()
}
}
}
}
}

0 comments on commit ed23b21

Please sign in to comment.