Skip to content

Commit

Permalink
Merge pull request #1193 from Microsoft/masterdetailsviewfix
Browse files Browse the repository at this point in the history
MasterDetailsView: fixed loaded bug
  • Loading branch information
shenchauhan authored May 31, 2017
2 parents 9374554 + 00245b7 commit f55a4c5
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public partial class MasterDetailsView : ItemsControl
private VisualStateGroup _stateGroup;
private VisualState _narrowState;
private Frame _frame;
private bool _loaded = false;

/// <summary>
/// Initializes a new instance of the <see cref="MasterDetailsView"/> class.
Expand Down Expand Up @@ -77,6 +78,17 @@ protected override void OnApplyTemplate()
SetMasterHeaderVisibility();
OnDetailsCommandBarChanged();
OnMasterCommandBarChanged();

if (_loaded && _stateGroup == null)
{
_stateGroup = (VisualStateGroup)GetTemplateChild(WidthStates);
if (_stateGroup != null)
{
_stateGroup.CurrentStateChanged += OnVisualStateChanged;
_narrowState = GetTemplateChild(NarrowState) as VisualState;
UpdateView(true);
}
}
}

/// <summary>
Expand Down Expand Up @@ -156,11 +168,14 @@ private void OnLoaded(object sender, RoutedEventArgs e)
}

_stateGroup = (VisualStateGroup)GetTemplateChild(WidthStates);
_stateGroup.CurrentStateChanged += OnVisualStateChanged;

_narrowState = GetTemplateChild(NarrowState) as VisualState;
if (_stateGroup != null)
{
_stateGroup.CurrentStateChanged += OnVisualStateChanged;
_narrowState = GetTemplateChild(NarrowState) as VisualState;
UpdateView(true);
}

UpdateView(true);
_loaded = true;
}

private void OnUnloaded(object sender, RoutedEventArgs e)
Expand All @@ -174,6 +189,12 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
frame.Navigating -= OnFrameNavigating;
}
}

if (_stateGroup != null)
{
_stateGroup.CurrentStateChanged -= OnVisualStateChanged;
_stateGroup = null;
}
}

/// <summary>
Expand Down

0 comments on commit f55a4c5

Please sign in to comment.