public void Detach(PhoneApplicationPage parentPage)
{
if (parentPage != this.page)
{
throw new InvalidOperationException();
}
if (this.page != parentPage)
{
return;
}
var binding = this.GetBindingExpression(DataContextProperty);
if (binding != null &&
binding.ParentBinding.Source == this.page)
{
this.DataContext = null;
}
this.DetachButtons(this.buttonsSourceButtons);
this.DetachButtons(this.Buttons);
this.DetachMenuItems(this.menuItemsSourceMenuItems);
this.DetachMenuItems(this.MenuItems);
this.applicationBar.StateChanged -=
this.ApplicationBarStateChanged;
this.applicationBar = null;
}
#endregion