private RibbonButtonGroup AddGroup(RibbonButtonModel groupModel) { RibbonButtonGroup groups = new RibbonButtonGroup() { GroupTitle = groupModel.Titel, Items = groupModel.Items }; groups.Click += (obj, args) => { if (Click != null) { Click(obj, args); } }; return(groups); }
public static void OnModelPropertyChanged(DependencyObject objects, DependencyPropertyChangedEventArgs args) { if (args.NewValue != null) { RibbonButton bases = objects as RibbonButton; RibbonButtonModel model = args.NewValue as RibbonButtonModel; if (model.Items.Count > 0) { bases.ribbonName.Text = model.Titel; bases.ribbonName.FontWeight = FontWeights.Medium; bases.ribbonName.Foreground = new SolidColorBrush(Color.FromArgb(100, 73, 95, 156)); } else { if (!model.IsActivate) { bases.IsEnabled = false; bases.Sign.Fill = new SolidColorBrush(Colors.Gray); } bases.ribbonName.Text = model.Titel; } } }
/// <summary> /// 加载tab控件的子元素 /// </summary> /// <param name="source"></param> private void LoadTabItems(RibbonTabButton source) { RibbonGroupPanel.Children.Clear(); ObservableCollection <RibbonButtonModel> tempSource = new ObservableCollection <RibbonButtonModel>(); #region 对数据进行分组 IEnumerable <RibbonButtonModel> groups = from hasChildGroup in source.Items where hasChildGroup.Items.Count > 0 select hasChildGroup; //获取拥有子元素的菜单 if (groups.Count() > 0) { foreach (var item in groups) { tempSource.Add(item); } } IEnumerable <RibbonButtonModel> NaNitemgroups = from NanChildGroup in source.Items where NanChildGroup.Items.Count <= 0 select NanChildGroup; if (NaNitemgroups.Count() > 0) { //对不包含子元素的菜单进行重组 ObservableCollection <RibbonButtonModel> restructureGroup = new ObservableCollection <RibbonButtonModel>(); foreach (var item in NaNitemgroups) { restructureGroup.Add(item); } RibbonButtonModel nanItemModel = new RibbonButtonModel() { Titel = source.Titel, Items = restructureGroup }; tempSource.Add(nanItemModel); } #endregion //对分组以及重组后的集合进行按元素多少进行排序 IEnumerable <RibbonButtonModel> orderSource = from groupItem in tempSource orderby groupItem.Items.Count descending select groupItem; double maxHeight = 0; //WrapPanel GroupParent = new WrapPanel() //{ // Orientation = Orientation.Vertical, // Margin = new Thickness(5, 5, 5, 5), // HorizontalAlignment = HorizontalAlignment.Center, // VerticalAlignment = VerticalAlignment.Center //}; StackPanel GroupParent = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(5, 5, 5, 5), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; foreach (RibbonButtonModel itemgroup in orderSource) { if (itemgroup.Items.Count > 0) { RibbonButtonGroup ribbongroups = AddGroup(itemgroup); ribbongroups.Margin = _groupMargin; if (maxHeight < ribbongroups.GroupHeight) { maxHeight = ribbongroups.GroupHeight; } GroupParent.Children.Add(ribbongroups); } } double ParentHeight = maxHeight + 8;// groupMargin.Bottom + groupMargin.Top;// +contentHeightOffset; GroupParent.Height = ParentHeight; RibbonGroupPanel.Children.Add(GroupParent); SetParentHeight(ParentHeight); #region 页面分割栏 Rectangle SplitLines = new Rectangle(); SplitLines.Height = 3; SplitLines.Fill = Application.Current.Resources["RibbonBarSplitLines1"] as Brush; Canvas.SetLeft(SplitLines, -1); Canvas.SetTop(SplitLines, -1.4); RibbonGroupPanel.Children.Add(SplitLines); #endregion GroupParent.SizeChanged += (obj, arg) => { RibbonGroupPanel.Width = arg.NewSize.Width + 12; SplitLines.Width = arg.NewSize.Width + 12; RibbonGroupParentPanel.Width = arg.NewSize.Width + 12; }; }