private void BuildModuleMenuTrivial(Panel trivialPanel, Accordion accordionPanel) { bool haveTrivialMenuItem = false; foreach (IModel model in MefExportedModels.Select(m => m.Value)) { foreach ( MethodInfo staticMethod in model.GetType().GetStaticMethodsForUserInterfaceAction(DataContext).Where( mi => mi.GetMethodParameters().Length == 1).ToArray()) { trivialPanel.Children.Add(staticMethod.GetControl(DataContext)); haveTrivialMenuItem = true; } } if (!haveTrivialMenuItem) { var label = new Label(); label.SetValue(ContentControl.ContentProperty, Properties.Resources.NoMenuAvailable); trivialPanel.Children.Add(label); } //collapse accordionPanel accordionPanel.SetValue(VisibilityProperty, Visibility.Collapsed); }
private void BuildModuleMenu(Panel trivialPanel, Accordion accordionPanel) { var controls = new object[] { trivialPanel, accordionPanel }; if (controls.Any(c => c == null)) { return; } //clear previous menu panels trivialPanel.Children.Clear(); if (accordionPanel.Items.Count > 0) { accordionPanel.Items.Clear(); } //check for design mode if (DesignModeCheck.IsInDesignModeStatic) { //MEF in design time is disabled var label = new Label(); label.SetValue(ContentControl.ContentProperty, Properties.Resources.NoDesignMenuAvailable); trivialPanel.Children.Add(label); //disable accordion trivialPanel accordionPanel.SetValue(VisibilityProperty, Visibility.Collapsed); return; } //switch on ModuleMenuType switch (ModuleMenuType) { case ModuleMenuType.Trivial: //call for Trivial menu BuildModuleMenuTrivial(trivialPanel, accordionPanel); break; case ModuleMenuType.Accordion: //call for Accordion menu BuildModuleMenuAccordion(trivialPanel, accordionPanel); break; default: throw new ArgumentOutOfRangeException(); } }
public virtual void ShouldHandleClearingTheSelectedIndicesProperty() { Accordion a = new Accordion(); IList<int> original = a.SelectedIndices; bool exceptionThrown = false; try { a.SetValue(Accordion.SelectedIndicesProperty, null); } catch (InvalidOperationException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); Assert.IsTrue(a.SelectedIndices.Count == 0); Assert.IsTrue(original == a.SelectedIndices); // reset test exceptionThrown = false; try { a.ClearValue(Accordion.SelectedIndicesProperty); } catch (InvalidOperationException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); Assert.IsTrue(a.SelectedIndices.Count == 0); Assert.IsTrue(original == a.SelectedIndices); }
private void BuildModuleMenuAccordion(Panel trivialPanel, Accordion accordionPanel) { bool haveAccordionMenuItem = false; var accordionMenuItems = new Dictionary <string, StackPanel>(); //collect manuItems foreach (var model in MefExportedModels.Select(m => m.Value)) { foreach (var staticMethod in model.GetType().GetStaticMethodsForUserInterfaceAction(DataContext) .Where(mi => mi.GetMethodParameters().Length == 1).ToArray()) { var displayAttribute = staticMethod.GetAttribute(() => new DisplayAttribute { GroupName = Properties.Resources.ModuleMenuOther }); var groupName = displayAttribute.GetGroupName() ?? Properties.Resources.ModuleMenuOther; var stackPanel = accordionMenuItems.TryGetValue(groupName, () => new StackPanel()); //add control to container stackPanel.Children.Add(staticMethod.GetControl(DataContext)); haveAccordionMenuItem = true; } } if (accordionMenuItems.Keys.Count > 1)//check for keys count... { //build menuItems foreach (var accordionMenuItemKey in accordionMenuItems.Keys) { //create scollviewer var scrollViewer = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Content = accordionMenuItems[accordionMenuItemKey] }; //create accordion item var accordionItem = new AccordionItem { Header = accordionMenuItemKey, Content = scrollViewer }; //add accordion item accordionPanel.Items.Add(accordionItem); } if (!haveAccordionMenuItem) { var label = new Label(); label.SetValue(ContentControl.ContentProperty, Properties.Resources.NoMenuAvailable); var accordionItem = new AccordionItem { Header = "", Content = label }; accordionPanel.Items.Add(accordionItem); } //collapse trivialPanel trivialPanel.SetValue(VisibilityProperty, Visibility.Collapsed); } else//one key only { //add to trivial menu foreach (var accordionMenuItemKey in accordionMenuItems.Keys) { trivialPanel.Children.Add(accordionMenuItems[accordionMenuItemKey]); } accordionPanel.SetValue(VisibilityProperty, Visibility.Collapsed); } }