public void Attach(PhoneApplicationPage parentPage)
{
this.page = parentPage;
this.applicationBar =
(ApplicationBar)(//parentPage.ApplicationBar ??
(parentPage.ApplicationBar = new ApplicationBar()));
this.applicationBar.StateChanged +=
this.ApplicationBarStateChanged;
if (this.GetBindingExpression(DataContextProperty) == null &&
this.DataContext == null)
{
this.SetBinding(
DataContextProperty,
new Binding("DataContext") { Source = this.page });
}
this.SynchronizeProperties();
this.AttachButtons(this.Buttons);
this.AttachButtons(this.buttonsSourceButtons);
this.AttachMenuItems(this.MenuItems);
this.AttachMenuItems(this.menuItemsSourceMenuItems);
if (this.Buttons != null && this.Buttons.Count > 0)
{
this.page.Loaded += this.OnPageLoaded;
}
}