Пример #1
0
        //TODO: Menu needs too long to render if there are too many items (> 20000).
        void contextMenu_Opened(object sender, RoutedEventArgs e)
        {
            contextMenu.Items.Clear();
            contextMenu.ItemTemplate         = ItemTemplate;
            contextMenu.ItemTemplateSelector = ItemTemplateSelector;

            //    List<MenuItem> menuItems = new List<MenuItem>();
            foreach (object item in Items)
            {
                if (!(item is MenuItem) && !(item is Separator))
                {
                    RibbonMenuItem menuItem = new RibbonMenuItem();
                    menuItem.DataContext = item;
                    BreadcrumbItem bi = item as BreadcrumbItem;
                    if (bi == null)
                    {
                        BreadcrumbItem parent = TemplatedParent as BreadcrumbItem;
                        if (parent != null)
                        {
                            bi = parent.ContainerFromItem(item);
                        }
                    }
                    if (bi != null)
                    {
                        menuItem.Header = bi.TraceValue;
                    }

                    Image image = new Image();
                    image.Source = bi != null ? bi.Image : null;
                    image.SnapsToDevicePixels = true;
                    image.Stretch             = Stretch.Fill;
                    image.VerticalAlignment   = VerticalAlignment.Center;
                    image.HorizontalAlignment = HorizontalAlignment.Center;
                    image.Width  = 16;
                    image.Height = 16;

                    menuItem.Icon = image;

                    menuItem.Click += new RoutedEventHandler(item_Click);
                    if (item != null && item.Equals(SelectedItem))
                    {
                        menuItem.FontWeight = FontWeights.Bold;
                    }
                    menuItem.ItemTemplate         = ItemTemplate;
                    menuItem.ItemTemplateSelector = ItemTemplateSelector;
                    contextMenu.Items.Add(menuItem);
                }
                else
                {
                    contextMenu.Items.Add(item);
                }
            }
            contextMenu.Placement       = PlacementMode.Relative;
            contextMenu.PlacementTarget = dropDownBtn;
            contextMenu.VerticalOffset  = dropDownBtn.ActualHeight;
        }
Пример #2
0
        void rItem_MouseEnter(object sender, MouseEventArgs e)
        {
            RibbonMenuItem item = sender as RibbonMenuItem;

            if (item.HasItems)
            {
                selectedItem = item;
                EnsureTimer().Start();
            }
        }
Пример #3
0
        void rItem_MouseLeave(object sender, MouseEventArgs e)
        {
            if (timer != null)
            {
                timer.Stop();
            }
            selectedItem = null;
            RibbonMenuItem item = sender as RibbonMenuItem;

            item.IsSubmenuOpen = false;
        }
Пример #4
0
        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Stop();
            RibbonMenuItem item = selectedItem;

            if (item != null)
            {
                MyFunc d = delegate() { item.IsSubmenuOpen = true; };
                this.Dispatcher.BeginInvoke(d);
            }
        }
Пример #5
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            RibbonMenuItem rItem = item as RibbonMenuItem;

            if (rItem != null)
            {
                rItem.MouseEnter += new MouseEventHandler(rItem_MouseEnter);
                rItem.MouseLeave += new MouseEventHandler(rItem_MouseLeave);
            }
        }
Пример #6
0
        private static void NamePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            string value = e.NewValue as string;

            IRibbonButton btn = o as IRibbonButton;

            if (btn != null)
            {
                btn.SmallImage = CreateImageSource(value, 16);
                btn.LargeImage = CreateImageSource(value, 32);
                return;
            }

            RibbonApplicationMenuItem apItem = o as RibbonApplicationMenuItem;

            if (apItem != null)
            {
                apItem.Image = CreateImageSource(value, 32);
                return;
            }

            RibbonMenuItem item = o as RibbonMenuItem;

            if (item != null)
            {
                item.Image = CreateImageSource(value, 16);
                return;
            }

            RibbonComboBox box = o as RibbonComboBox;

            if (box != null)
            {
                box.Image = CreateImageSource(value, 16);
                return;
            }

            RibbonTextBox tb = o as RibbonTextBox;

            if (tb != null)
            {
                tb.Image = CreateImageSource(value, 16);
                return;
            }

            throw new ArgumentNullException("RibbonSrc.Name can only by attached to controls that implement IRibbonButton.");
        }
Пример #7
0
        /// <summary>
        /// Build the list of traces for the overflow button.
        /// </summary>
        private void BuildTraces()
        {
            BreadcrumbItem item = RootItem;

            traces.Clear();
            if (item != null && item.IsOverflow)
            {
                foreach (object trace in item.Items)
                {
                    MenuItem menuItem = new RibbonMenuItem();
                    menuItem.Tag = trace;
                    BreadcrumbItem bcItem = item.ContainerFromItem(trace);

                    menuItem.Click += new RoutedEventHandler(menuItem_Click);
                    menuItem.Icon = GetImage(bcItem != null ? bcItem.Image : null);
                    if (trace == RootItem.SelectedItem) menuItem.FontWeight = FontWeights.Bold;
                    traces.Add(menuItem);
                    if (bcItem != null) menuItem.Header = bcItem.TraceValue;
                }
                traces.Insert(0, new Separator());
                MenuItem rootMenuItem = new RibbonMenuItem();
                rootMenuItem.Header = item.TraceValue;
                rootMenuItem.Command = BreadcrumbBar.SelectRootCommand;
                rootMenuItem.CommandParameter = item;
                rootMenuItem.Icon = GetImage(item.Image);
                traces.Insert(0, rootMenuItem);
            }

            item = item != null ? item.SelectedBreadcrumb : null;

            while (item != null)
            {
                if (!item.IsOverflow) break;
                MenuItem traceMenuItem = new MenuItem();
                traceMenuItem.Header = item.TraceValue;
                traceMenuItem.Command = BreadcrumbBar.SelectRootCommand;
                traceMenuItem.CommandParameter = item;
                traceMenuItem.Icon = GetImage(item.Image);
                traces.Insert(0, traceMenuItem);
                item = item.SelectedBreadcrumb;
            }
        }
 void rItem_MouseEnter(object sender, MouseEventArgs e)
 {
     RibbonMenuItem item = sender as RibbonMenuItem;
     if (item.HasItems)
     {
         selectedItem = item;
         EnsureTimer().Start();
     }
 }
 void rItem_MouseLeave(object sender, MouseEventArgs e)
 {
     if (timer != null) timer.Stop();
     selectedItem = null;
     RibbonMenuItem item = sender as RibbonMenuItem;
     item.IsSubmenuOpen = false;
 }
        //TODO: Menu needs too long to render if there are too many items (> 20000).
        void contextMenu_Opened(object sender, RoutedEventArgs e)
        {
            contextMenu.Items.Clear();
            //contextMenu.ItemTemplate = this.bre.BreadcrumbBar.DropDownItemTemplate;
            //contextMenu.ItemTemplateSelector = bi.BreadcrumbBar.DropDownItemTemplateSelector;

        //    List<MenuItem> menuItems = new List<MenuItem>();
            foreach (object item in Items)
            {
                if (!(item is MenuItem) && !(item is Separator))
                {
                    RibbonMenuItem menuItem = new RibbonMenuItem();
                    menuItem.DataContext = item;
                    BreadcrumbItem bi = item as BreadcrumbItem;

                    if (bi == null)
                    {
                        BreadcrumbItem parent = TemplatedParent as BreadcrumbItem;
                        if (parent != null) bi = parent.ContainerFromItem(item);
                    }
                    if (bi != null)
                    {
                        if (bi.BreadcrumbBar.DropDownItemTemplate == null)
                        {
                            menuItem.Header = bi.TraceValue;
                            menuItem.Background = new SolidColorBrush(Colors.Yellow);

                            Image image = new Image();
                            image.Source = bi != null ? bi.Image : null;
                            image.SnapsToDevicePixels = true;
                            image.Stretch = Stretch.Fill;
                            image.VerticalAlignment = VerticalAlignment.Center;
                            image.HorizontalAlignment = HorizontalAlignment.Center;
                            image.Width = 16;
                            image.Height = 16;

                            menuItem.Icon = image;      
                        }
                        else
                        {
                            contextMenu.ItemTemplate = bi.BreadcrumbBar.DropDownItemTemplate;
                            menuItem.ItemTemplate = bi.BreadcrumbBar.DropDownItemTemplate;
                        }
                    }                                

                    menuItem.Click += new RoutedEventHandler(item_Click);
                    if (item != null && item.Equals(SelectedItem)) menuItem.FontWeight = FontWeights.Bold;
                    contextMenu.Items.Add(menuItem);
                }
                else
                {
                    //contextMenu.ItemTemplate = bi.BreadcrumbBar.DropDownItemTemplate;
                    //menuItem.ItemTemplate = bi.BreadcrumbBar.DropDownItemTemplate;

                    contextMenu.Items.Add(item);
                }
            }
            contextMenu.Placement = PlacementMode.Relative;
            contextMenu.PlacementTarget = dropDownBtn;
            contextMenu.VerticalOffset = dropDownBtn.ActualHeight;
        }
Пример #11
0
		//TODO: Menu needs too long to render if there are too many items (> 20000).
		private void contextMenu_Opened(object sender, RoutedEventArgs e)
		{
			contextMenu.Items.Clear();
			contextMenu.ItemTemplate = ItemTemplate;
			contextMenu.ItemTemplateSelector = ItemTemplateSelector;

			//    List<MenuItem> menuItems = new List<MenuItem>();
			foreach (object item in Items)
			{
				if (!(item is MenuItem) && !(item is Separator))
				{
					var menuItem = new RibbonMenuItem();
					menuItem.DataContext = item;
					var bi = item as BreadcrumbItem;
					if (bi == null)
					{
						var parent = TemplatedParent as BreadcrumbItem;
						if (parent != null)
							bi = parent.ContainerFromItem(item);
					}
					if (bi != null)
						menuItem.Header = bi.TraceValue;

					var image = new Image();
					image.Source = bi != null
						? bi.Image
						: null;
					image.SnapsToDevicePixels = true;
					image.Stretch = Stretch.Fill;
					image.VerticalAlignment = VerticalAlignment.Center;
					image.HorizontalAlignment = HorizontalAlignment.Center;
					image.Width = 16;
					image.Height = 16;

					menuItem.Icon = image;

					menuItem.Click += item_Click;
					if (item != null && item.Equals(SelectedItem))
						menuItem.FontWeight = FontWeights.Bold;
					menuItem.ItemTemplate = ItemTemplate;
					menuItem.ItemTemplateSelector = ItemTemplateSelector;
					contextMenu.Items.Add(menuItem);
				}
				else
				{
					contextMenu.Items.Add(item);
				}
			}
			contextMenu.Placement = PlacementMode.Relative;
			contextMenu.PlacementTarget = dropDownBtn;
			contextMenu.VerticalOffset = dropDownBtn.ActualHeight;
		}