public void TitleBar_properties_synchronised_with_ribbon() { var ribbon = new Ribbon { ContextualGroups = { new RibbonContextualTabGroup() } }; using (new TestRibbonWindow(ribbon)) { ribbon.ApplyTemplate(); Assert.IsNotNull(ribbon.QuickAccessToolBar); var oldTitleBar = ribbon.TitleBar = new RibbonTitleBar(); Assert.AreEqual(1, oldTitleBar.Items.Count); Assert.AreSame(ribbon.QuickAccessToolBar, oldTitleBar.QuickAccessToolBar); var newTitleBar = new RibbonTitleBar(); Assert.AreEqual(0, newTitleBar.Items.Count); Assert.IsNull(newTitleBar.QuickAccessToolBar); // assign a new title bar, the contextual groups and quick access are transferred across ribbon.TitleBar = newTitleBar; Assert.AreEqual(0, oldTitleBar.Items.Count); Assert.IsNull(oldTitleBar.QuickAccessToolBar); Assert.AreEqual(1, newTitleBar.Items.Count); Assert.AreSame(ribbon.QuickAccessToolBar, newTitleBar.QuickAccessToolBar); // remove the title bar ribbon.TitleBar = null; Assert.AreEqual(0, oldTitleBar.Items.Count); Assert.IsNull(oldTitleBar.QuickAccessToolBar); Assert.AreEqual(0, newTitleBar.Items.Count); Assert.IsNull(newTitleBar.QuickAccessToolBar); } }
public void DependencyProperties_and_DataContext_should_be_inherited_from_window() { var ribbon = new Ribbon { Menu = new Backstage(), StartScreen = new StartScreen() }; var enUs = XmlLanguage.GetLanguage("en-US"); var deDe = XmlLanguage.GetLanguage("de-DE"); using (var window = new TestRibbonWindow(ribbon) { Language = deDe, DataContext = deDe }) { ribbon.ApplyTemplate(); var elemens = new Dictionary <FrameworkElement, string> { { ribbon, "Ribbon" }, { ribbon.Menu, "Menu" }, { ribbon.StartScreen, "StartScreen" }, { ribbon.QuickAccessToolBar, "QuickAccessToolBar" }, { ribbon.TabControl, "TabControl" }, { (FrameworkElement)ribbon.Template.FindName("PART_LayoutRoot", ribbon), "PART_LayoutRoot" }, }; { AssertAttElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window); AssertAttElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window); } { window.Language = enUs; window.DataContext = window.Language; AssertAttElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window); AssertAttElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window); } { window.Language = deDe; window.DataContext = window.Language; AssertAttElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window); AssertAttElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window); } { window.Language = enUs; window.DataContext = window.Language; AssertAttElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window); AssertAttElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window); } } }