Ejemplo n.º 1
0
        void item_MouseEnter(object sender, MouseEventArgs e)
        {
            isUsingRibbon = true;
            RibbonTabButton source = sender as RibbonTabButton;

            if (source.Items.Count <= 0)
            {
                source.MouseLeftButtonDown += (obj, args) =>
                {
                    if (Click != null)
                    {
                        Click(source, new RibbonButtonClickArgs()
                        {
                            DataContext = source.DataContext
                        });
                    }
                };
            }
            else
            {
                #region Load Items
                Point currentPoint = new Point()
                {
                    X = Canvas.GetLeft(source) + ContentMargin.Left
                };
                if (!isClick)
                {
                    LoadTabItems(source);
                    RibbonGroupParentPanel.Visibility = Visibility.Visible;
                    TabSelectedBackground.Width       = source.Width + clickOffset * 2;
                    Canvas.SetLeft(TabSelectedBackground, currentPoint.X - clickOffset);
                    Canvas.SetLeft(RibbonGroupParentPanel, currentPoint.X - clickOffset * 3);
                    ChangeVisualState("Show", false);
                    isClick = true;
                }
                else
                {
                    LoadTabItems(source);
                    double tabprevleft      = Canvas.GetLeft(TabSelectedBackground);
                    double panelprevleft    = Canvas.GetLeft(RibbonGroupParentPanel);
                    double tabcurrentleft   = currentPoint.X - clickOffset;
                    double panelcurrentleft = currentPoint.X - clickOffset * 3;

                    List <IModel> _models = new List <IModel>()
                    {
                        new Model.DoubleModel()
                        {
                            Target = TabSelectedBackground, From = tabprevleft, To = tabcurrentleft, PropertyPath = ConstPropertyPath.CANVAS_LEFT, Duration = 0.2
                        },
                        new Model.DoubleModel()
                        {
                            Target = RibbonGroupParentPanel, From = panelprevleft, To = panelcurrentleft, PropertyPath = ConstPropertyPath.CANVAS_LEFT, Duration = 0.2
                        }
                    };
                    Engine.CreateStoryboard(_models).Begin();
                }
                TabSelectedBackground.BorderThickness = new Thickness(1, 1, 1, 0);
                #endregion
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载RibbonBar子元素
        /// </summary>
        private void LoadItems()
        {
            if (Items != null)
            {
                double maxLeft   = 0;
                double maxTop    = 0;
                double centerTop = 0;
                for (int i = 0; i < Items.Count; i++)
                {
                    #region 添加TabButton,即RibbonBarItem
                    RibbonTabButton item = Items[i];
                    Point           size = GetTextWidthHeight(item.Titel, item.txbtitel);
                    maxLeft                  += size.X;
                    item.txbtitel.Text        = item.Titel;
                    item.Width                = size.X + RibbonTabButton.OffsetWidth;
                    item.Height               = RibbonTabContent.Height;
                    item.MouseLeftButtonDown += new MouseButtonEventHandler(item_MouseLeftButtonDown);
                    item.MouseEnter          += new MouseEventHandler(item_MouseEnter);
                    item.MouseLeave          += new MouseEventHandler(item_MouseLeave);
                    #endregion
                    #region 添加分隔符
                    if (i != 0)
                    {
                        Rectangle SplitLines = new Rectangle();
                        SplitLines.Height = 14;
                        SplitLines.Width  = 2;
                        SplitLines.Margin = new Thickness(1, 10, 1, 0);
                        LinearGradientBrush _l = new LinearGradientBrush();
                        _l.StartPoint = new Point(0, 0.5);
                        _l.EndPoint   = new Point(1, 0.5);
                        GradientStop _G1 = new GradientStop();
                        _G1.Color  = Color.FromArgb(255, 8, 39, 99);
                        _G1.Offset = 0;
                        GradientStop _G2 = new GradientStop();

                        _G2.Color  = Color.FromArgb(255, 8, 39, 99);
                        _G2.Offset = 0.5;
                        GradientStop _G3 = new GradientStop();
                        _G3.Color  = Color.FromArgb(175, 255, 255, 255);
                        _G3.Offset = 0.5;
                        GradientStop _G4 = new GradientStop();
                        _G4.Color  = Color.FromArgb(175, 255, 255, 255);
                        _G4.Offset = 1;
                        _l.GradientStops.Add(_G1);
                        _l.GradientStops.Add(_G2);
                        _l.GradientStops.Add(_G3);
                        _l.GradientStops.Add(_G4);
                        SplitLines.Fill = _l;
                        SplitLines.HorizontalAlignment = HorizontalAlignment.Left;

                        Canvas.SetLeft(SplitLines, maxLeft + tabButtonMargint / 2 - 2);
                        RibbonTabContent.Children.Add(SplitLines);
                        maxLeft += tabButtonMargint;
                    }
                    #endregion

                    Canvas.SetLeft(item, maxLeft);
                    RibbonTabContent.Children.Add(item);
                    //maxLeft += size.X+=4;
                }

                SetRibbonBarWidth(maxLeft + ContentMargin.Right + ContentMargin.Left);
            }
        }
Ejemplo n.º 3
0
        /// <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;
            };
        }