Exemple #1
0
        private static void TracePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem breadcrumbItem = sender as BreadcrumbItem;
            RoutedPropertyChangedEventArgs <object> e2 = new RoutedPropertyChangedEventArgs <object>(e.OldValue, e.NewValue, BreadcrumbItem.TraceChangedEvent);

            breadcrumbItem.RaiseEvent(e2);
        }
Exemple #2
0
        public void ApplyBinding()
        {
            object dataContext = base.DataContext;

            if (dataContext != null)
            {
                DataTemplate         dataTemplate           = this.HeaderTemplate;
                DataTemplateSelector headerTemplateSelector = this.HeaderTemplateSelector;
                if (headerTemplateSelector != null)
                {
                    dataTemplate = headerTemplateSelector.SelectTemplate(dataContext, this);
                }
                if (dataTemplate == null)
                {
                    DataTemplateKey resourceKey = BreadcrumbItem.GetResourceKey(dataContext);
                    if (resourceKey != null)
                    {
                        dataTemplate = (base.TryFindResource(resourceKey) as DataTemplate);
                    }
                }
                this.SelectedItem = null;
                HierarchicalDataTemplate hierarchicalDataTemplate = dataTemplate as HierarchicalDataTemplate;
                if (dataTemplate != null)
                {
                    this.Header = dataTemplate.LoadContent();
                }
                else
                {
                    this.Header = dataContext;
                }
                this.DataContext = dataContext;
                if (hierarchicalDataTemplate != null)
                {
                    this.SetBinding(ItemsControl.ItemsSourceProperty, hierarchicalDataTemplate.ItemsSource);
                }
                BreadcrumbBar breadcrumbBar = this.BreadcrumbBar;
                if (breadcrumbBar != null)
                {
                    if (this.TraceBinding == null)
                    {
                        this.TraceBinding = breadcrumbBar.TraceBinding;
                    }
                    if (this.ImageBinding == null)
                    {
                        this.ImageBinding = breadcrumbBar.ImageBinding;
                    }
                }
                if (this.TraceBinding != null)
                {
                    this.SetBinding(BreadcrumbItem.TraceProperty, this.TraceBinding);
                }
                if (this.ImageBinding != null)
                {
                    this.SetBinding(BreadcrumbItem.ImageProperty, this.ImageBinding);
                }
                this.ApplyProperties(dataContext);
            }
        }
Exemple #3
0
        void contextMenu_Opened(object sender, RoutedEventArgs e)
        {
            contextMenu.Items.Clear();
            contextMenu.ItemTemplate         = ItemTemplate;
            contextMenu.ItemTemplateSelector = ItemTemplateSelector;
            foreach (object item in Items)
            {
                if (!(item is MenuItem) && !(item is Separator))
                {
                    MenuItem menuItem = new MenuItem();
                    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.Background = Brushes.LightSkyBlue;
                    }
                    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;
        }
Exemple #4
0
        public static BreadcrumbItem CreateItem(object dataContext)
        {
            BreadcrumbItem breadcrumbItem = dataContext as BreadcrumbItem;

            if (breadcrumbItem == null && dataContext != null)
            {
                breadcrumbItem             = new BreadcrumbItem();
                breadcrumbItem.DataContext = dataContext;
            }
            return(breadcrumbItem);
        }
Exemple #5
0
        public BreadcrumbItem ContainerFromItem(object item)
        {
            BreadcrumbItem breadcrumbItem = item as BreadcrumbItem;

            if (breadcrumbItem == null)
            {
                breadcrumbItem = BreadcrumbItem.CreateItem(item);
                if (breadcrumbItem != null)
                {
                    base.AddLogicalChild(breadcrumbItem);
                    breadcrumbItem.ApplyTemplate();
                }
            }
            return(breadcrumbItem);
        }
Exemple #6
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);
        }
Exemple #7
0
        public object GetTraceItem(string trace)
        {
            object result;

            foreach (object current in ((IEnumerable)base.Items))
            {
                BreadcrumbItem breadcrumbItem = this.ContainerFromItem(current);
                if (current == null)
                {
                    result = null;
                    return(result);
                }
                string traceValue = breadcrumbItem.TraceValue;
                if (traceValue != null && traceValue.Equals(trace, StringComparison.InvariantCultureIgnoreCase))
                {
                    result = current;
                    return(result);
                }
            }
            result = null;
            return(result);
        }
Exemple #8
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 (item != null)
         {
             //ApplyProperties(item);
             string value = bcItem.TraceValue;
             if (value != null && value.Equals(trace, StringComparison.InvariantCultureIgnoreCase))
             {
                 return(item);
             }
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
 public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
 }
Exemple #10
0
 public ApplyPropertiesEventArgs(object item, BreadcrumbItem breadcrumb, RoutedEvent routedEvent) : base(routedEvent)
 {
     this.Item       = item;
     this.Breadcrumb = breadcrumb;
 }
Exemple #11
0
        public static void OverflowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem breadcrumbItem = d as BreadcrumbItem;

            breadcrumbItem.OnOverflowChanged((bool)e.NewValue);
        }
Exemple #12
0
        public static void DropDownPressedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem breadcrumbItem = d as BreadcrumbItem;

            breadcrumbItem.OnDropDownPressedChanged();
        }
Exemple #13
0
        private static void SelectedBreadcrumbPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem breadcrumbItem = d as BreadcrumbItem;

            breadcrumbItem.OnSelectedBreadcrumbChanged(e.OldValue, e.NewValue);
        }
Exemple #14
0
 private static void HeaderPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
 {
     BreadcrumbItem breadcrumbItem = sender as BreadcrumbItem;
 }
Exemple #15
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);
        }
Exemple #16
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            BreadcrumbItem item = new BreadcrumbItem();

            return(item);
        }