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

MasterDetailsView: fixed loaded bug #1193

Merged
merged 2 commits into from
May 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to unwire this when it's unloaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

_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