void SetActiveBarItem(BarItem sharedBarItem, BarItem activeBarItem) { sharedBarItem.Tag = activeBarItem; BarCheckItem sharedBarCheckItem = sharedBarItem as BarCheckItem; BarEditItem sharedBarEditItem = sharedBarItem as BarEditItem; if (activeBarItem == null) { sharedBarItem.IsEnabled = false; sharedBarItem.Content = sharedBarItem.Content; sharedBarItem.Glyph = sharedBarItem.Glyph; sharedBarItem.LargeGlyph = sharedBarItem.LargeGlyph; sharedBarItem.Hint = sharedBarItem.Hint; sharedBarItem.GlyphAlignment = sharedBarItem.GlyphAlignment; if (sharedBarEditItem != null) { object editValue = sharedBarEditItem.EditValue; BindingOperations.ClearBinding(sharedBarEditItem, BarEditItem.EditValueProperty); sharedBarEditItem.EditValue = editValue; } if (sharedBarCheckItem != null) { DepPropertyHelper.UnbindHard(sharedBarCheckItem, BarCheckItem.IsCheckedProperty); } } else { sharedBarItem.SetBinding(BarItem.IsEnabledProperty, new Binding("IsEnabled") { Source = activeBarItem, Mode = BindingMode.OneWay }); sharedBarItem.SetBinding(BarItem.ContentProperty, new Binding("Content") { Source = activeBarItem, Mode = BindingMode.OneWay }); sharedBarItem.SetBinding(BarItem.GlyphProperty, new Binding("Glyph") { Source = activeBarItem, Mode = BindingMode.OneWay }); sharedBarItem.SetBinding(BarItem.LargeGlyphProperty, new Binding("LargeGlyph") { Source = activeBarItem, Mode = BindingMode.OneWay }); sharedBarItem.SetBinding(BarItem.HintProperty, new Binding("Hint") { Source = activeBarItem, Mode = BindingMode.OneWay }); sharedBarItem.SetBinding(BarItem.GlyphAlignmentProperty, new Binding("GlyphAlignment") { Source = activeBarItem, Mode = BindingMode.OneWay }); if (sharedBarItem is BarEditItem) { sharedBarItem.SetBinding(BarEditItem.EditValueProperty, new Binding("EditValue") { Source = activeBarItem, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); } if (sharedBarCheckItem != null) { DepPropertyHelper.BindHard(sharedBarCheckItem, BarCheckItem.IsCheckedProperty, activeBarItem, BarCheckItem.IsCheckedProperty); } } }