コード例 #1
0
ファイル: RibbonButtonGroup.xaml.cs プロジェクト: jjg0519/OA
 public static void OnItemsPropertyChanged(DependencyObject objects, DependencyPropertyChangedEventArgs args)
 {
     if (args.NewValue != null)
     {
         RibbonButtonGroup bases = objects as RibbonButtonGroup;
         bases.LoadItems();
     }
 }
コード例 #2
0
ファイル: RibbonBar.xaml.cs プロジェクト: jjg0519/OA
        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);
        }
コード例 #3
0
ファイル: RibbonBar.xaml.cs プロジェクト: jjg0519/OA
        /// <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;
            };
        }