Пример #1
0
        private static void TracePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = sender as BreadcrumbItem;

            RoutedPropertyChangedEventArgs <object> args = new RoutedPropertyChangedEventArgs <object>(e.OldValue, e.NewValue, TraceChangedEvent);

            item.RaiseEvent(args);
        }
Пример #2
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;
        }
Пример #3
0
        /// <summary>
        /// Creates a new BreadcrumbItem out of the specified data.
        /// </summary>
        /// <param name="dataContext">The DataContext for the BreadcrumbItem</param>
        /// <returns>DataContext if dataContext is a Breadcrumbitem, otherwhise a new BreadcrumbItem.</returns>
        public static BreadcrumbItem CreateItem(object dataContext)
        {
            BreadcrumbItem item = dataContext as BreadcrumbItem;

            if (item == null && dataContext != null)
            {
                item             = new BreadcrumbItem();
                item.DataContext = dataContext;
            }
            return(item);
        }
Пример #4
0
        /// <summary>
        /// Generates a new BreadcrumbItem out of the specified item.
        /// </summary>
        /// <param name="item">The item for which to create a new BreadcrumbItem.</param>
        /// <returns>Item, if item is a BreadcrumbItem, otherwhise a newly created BreadcrumbItem.</returns>
        public BreadcrumbItem ContainerFromItem(object item)
        {
            BreadcrumbItem result = item as BreadcrumbItem;

            if (result == null)
            {
                result = CreateItem(item);
                if (result != null)
                {
                    AddLogicalChild(result);
                    result.ApplyTemplate();
                }
            }
            return(result);
        }
Пример #5
0
 /// <summary>
 /// Gets the item that represents the specified trace otherwise null.
 /// </summary>
 /// <param name="trace">The Trace property of the associated BreadcrumbItem.</param>
 /// <returns>An object included in Items, otherwise null.</returns>
 public object GetTraceItem(string trace)
 {
     this.ApplyTemplate();
     foreach (object item in Items)
     {
         BreadcrumbItem bcItem = ContainerFromItem(item);
         if (bcItem != null)
         {
             ApplyProperties(item);
             string value = bcItem.TraceValue;
             if (value != null && value.Equals(trace, StringComparison.InvariantCultureIgnoreCase))
             {
                 return(item);
             }
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Пример #6
0
 public ApplyPropertiesEventArgs(object item, BreadcrumbItem breadcrumb, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item       = item;
     Breadcrumb = breadcrumb;
 }
Пример #7
0
        /// <summary>
        ///  Appies the binding to the breadcrumb item.
        /// </summary>
        public void ApplyBinding()
        {
            object item = DataContext;

            if (item == null)
            {
                return;
            }

            BreadcrumbItem       root             = this;
            DataTemplate         template         = HeaderTemplate;
            DataTemplateSelector templateSelector = HeaderTemplateSelector;

            if (templateSelector != null)
            {
                template = templateSelector.SelectTemplate(item, root);
            }
            if (template == null)
            {
                DataTemplateKey key = GetResourceKey(item);
                if (key != null)
                {
                    template = TryFindResource(key) as DataTemplate;
                }
            }

            root.SelectedItem = null;

            HierarchicalDataTemplate hdt = template as HierarchicalDataTemplate;

            if (template != null)
            {
                root.Header = template.LoadContent();
            }
            else
            {
                root.Header = item;
            }
            root.DataContext = item;

            if (hdt != null)
            {
                // bind the Items to the hierarchical data template:
                root.SetBinding(BreadcrumbItem.ItemsSourceProperty, hdt.ItemsSource);
            }

            BreadcrumbBar bar = BreadcrumbBar;

            if (bar != null)
            {
                if (TraceBinding == null)
                {
                    TraceBinding = bar.TraceBinding;
                }
                if (ImageBinding == null)
                {
                    ImageBinding = bar.ImageBinding;
                }
            }

            if (TraceBinding != null)
            {
                root.SetBinding(BreadcrumbItem.TraceProperty, TraceBinding);
            }
            if (ImageBinding != null)
            {
                root.SetBinding(BreadcrumbItem.ImageProperty, ImageBinding);
            }


            ApplyProperties(item);
        }
Пример #8
0
        /// <summary>
        /// Occurs when the Overflow property is changed.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        public static void OverflowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnOverflowChanged((bool)e.NewValue);
        }
Пример #9
0
        /// <summary>
        /// Occurs when the IsDropDownPressed property is changed.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        public static void DropDownPressedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnDropDownPressedChanged();
        }
Пример #10
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            BreadcrumbItem item = new BreadcrumbItem();

            return(item);
        }
Пример #11
0
        private static void SelectedBreadcrumbPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnSelectedBreadcrumbChanged(e.OldValue, e.NewValue);
        }
Пример #12
0
 private static void HeaderPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
 {
     BreadcrumbItem item = sender as BreadcrumbItem;
 }
Пример #13
0
 public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
 }