private void TracePropertyChanged(BreadcrumbItem sender, AvaloniaPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = sender as BreadcrumbItem;

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

            item.RaiseEvent(args);
        }
        private void breadcrumbItemSelectionChangedEvent(object sender, RoutedEventArgs e)
        {
            BreadcrumbItem parent = e.Source as BreadcrumbItem;

            if (parent != null && parent.SelectedBreadcrumb != null)
            {
                OnPopulateItems(parent.SelectedBreadcrumb);
            }
        }
        private void SelectTraceCommandExecuted(object sender)
        {
            BreadcrumbItem item = sender as BreadcrumbItem;

            if (item != null)
            {
                item.SelectedItem = null;
            }
        }
        private void OnSelectedBreadcrumbPropertyChanged(BreadcrumbBar bar, AvaloniaPropertyChangedEventArgs e)
        {
            BreadcrumbItem selected = e.NewValue as BreadcrumbItem;

            bar.IsRootSelected = selected == bar.RootItem;
            if (bar.IsInitialized)
            {
                RoutedPropertyChangedEventArgs <BreadcrumbItem> args = new RoutedPropertyChangedEventArgs <BreadcrumbItem>(e.OldValue as BreadcrumbItem, e.NewValue as BreadcrumbItem, BreadcrumbBar.SelectedBreadcrumbChangedEvent);
                bar.RaiseEvent(args);
            }
        }
        /// <summary>
        /// creates the initial Breadcrumb item
        /// </summary>
        /// <param name="dataContext"></param>
        /// <returns></returns>
        internal static BreadcrumbItem CreateInitialItem(object dataContext)
        {
            BreadcrumbItem item = dataContext as BreadcrumbItem;

            if (item == null && dataContext != null)
            {
                item       = new BreadcrumbItem();
                item.Items = dataContext as IEnumerable;
            }
            return(item);
        }
        /// <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);
        }
        private void breadcrumbItemDropDownChangedEvent(object sender, RoutedEventArgs e)
        {
            BreadcrumbItem breadcrumb = e.Source as BreadcrumbItem;

            if (breadcrumb.IsDropDownPressed)
            {
                OnBreadcrumbItemDropDownOpened(e);
            }
            else
            {
                OnBreadcrumbItemDropDownClosed(e);
            }
        }
        /// <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 MenuItem();//new RibbonMenuItem();
                    menuItem.Tag = trace;
                    BreadcrumbItem bcItem = item.ContainerFromItem(trace);

                    menuItem.Click += menuItem_Click;
                    menuItem.Icon   = GetImage(bcItem != null ? bcItem.Image : null);
                    if (trace == RootItem.SelectedItem)
                    {
                        menuItem.FontWeight = FontWeight.Bold;
                    }
                    traces.Add(menuItem);
                    if (bcItem != null)
                    {
                        menuItem.Header = bcItem.TraceValue;
                    }
                }
                traces.Insert(0, new Separator());
                MenuItem rootMenuItem = new MenuItem();//new RibbonMenuItem();
                rootMenuItem.Header           = item.TraceValue;
                rootMenuItem.Command          = 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          = SelectRootCommand;
                traceMenuItem.CommandParameter = item;
                traceMenuItem.Icon             = GetImage(item.Image);
                traces.Insert(0, traceMenuItem);
                item = item.SelectedBreadcrumb;
            }
        }
        /// <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)
                {
                    LogicalChildren.Add(result);
                    result.ApplyTemplate();
                }
            }
            return(result);
        }
        private void breadcrumbItemSelectedItemChanged(object sender, RoutedEventArgs e)
        {
            BreadcrumbItem breadcrumb = e.Source as BreadcrumbItem;

            if (breadcrumb != null && breadcrumb.SelectedBreadcrumb != null)
            {
                breadcrumb = breadcrumb.SelectedBreadcrumb;
            }
            SelectedBreadcrumb = breadcrumb;

            if (SelectedBreadcrumb != null)
            {
                SelectedItem = SelectedBreadcrumb.Data;
            }
            Path = GetEditPath();
        }
        /// <summary>
        /// Occurs when the IsDropDownPressed property is changed.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private void DropDownPressedPropertyChanged(BreadcrumbItem o, AvaloniaPropertyChangedEventArgs e)
        {
            if (e.NewValue is bool)
            {
                bool value = (bool)e.NewValue;
                if (lastValue == value)
                {
                    return;
                }

                BreadcrumbItem item = o as BreadcrumbItem;
                item.OnDropDownPressedChanged();

                lastValue = value;
            }
        }
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);
            comboBox   = e.NameScope.Find <ComboBox>(partComboBox);
            rootButton = e.NameScope.Find <BreadcrumbButton>(partRoot);

            ToggleButton toggleButton = e.NameScope.Find <ToggleButton>("dropDown");

            //toggleButton.Checked += (o, e) =>
            //{
            //    if (toggleButton.IsChecked == true)
            //    {
            //        IsDropDownOpen = true;
            //    }
            //    else
            //    {
            //        IsDropDownOpen = false;
            //    }

            //};

            if (comboBox != null)
            {
                //comboBox.DropDownClosed += new EventHandler(comboBox_DropDownClosed);
                comboBox.PropertyChanged += ComboBox_PropertyChanged;

                //comboBox.IsKeyboardFocusWithinChanged += new DependencyPropertyChangedEventHandler(comboBox_IsKeyboardFocusWithinChanged);
                comboBox.KeyDown += comboBox_KeyDown;

                PseudoClasses.Set(":comboBoxIsVisible", comboBox.IsVisible);
            }
            if (rootButton != null)
            {
                rootButton.PointerPressed += rootButton_Click;
            }

            BreadcrumbItem breadcrumbItem = Content as BreadcrumbItem;

            _isInitial = true;
            RaisePropertyChanged(RootProperty, null, breadcrumbItem.Items);
            _isInitial = false;

            //RaisePropertyChanged(PathProperty, string.Empty, Path);
        }
Esempio n. 13
0
        private MenuItem CreateMenuItem(object item)
        {
            //RibbonMenuItem menuItem = new RibbonMenuItem();
            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   = Layout.VerticalAlignment.Center;
            image.HorizontalAlignment = Layout.HorizontalAlignment.Center;
            image.Width  = 16;
            image.Height = 16;

            menuItem.Icon = image;

            menuItem.Click += item_Click;// += new RoutedEventHandler(item_Click);
            if (item != null && item.Equals(SelectedItem))
            {
                menuItem.FontWeight = FontWeight.Bold;
            }
            menuItem.ItemTemplate = ItemTemplate;
            //menuItem.ItemTemplateSelector = ItemTemplateSelector;
            //contextMenu.Items.OfType<object>().ToList().Add(menuItem);
            return(menuItem);
        }
 /// <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);
 }
        /// <summary>
        /// Gets the path of the specified BreadcrumbItem.
        /// </summary>
        /// <param name="item">The BreadrumbItem for which to determine the path.</param>
        /// <returns>The path of the BreadcrumbItem which is the concenation of all Traces from all selected breadcrumbs.</returns>
        public string PathFromBreadcrumbItem(BreadcrumbItem item)
        {
            StringBuilder sb = new StringBuilder();

            while (item != null)
            {
                if (item == RootItem && sb.Length > 0)
                {
                    break;
                }
                if (sb.Length > 0)
                {
                    sb.Insert(0, SeparatorString);
                }
                sb.Insert(0, item.TraceValue);
                item = item.ParentBreadcrumbItem;
            }
            PathConversionEventArgs e = new PathConversionEventArgs(ConversionMode.DisplayToEdit, sb.ToString(), Root, PathConversionEvent);

            RaiseEvent(e);
            return(e.EditPath);
        }
        /// <summary>
        /// Gets the display path from the traces of the BreacrumbItems.
        /// </summary>
        /// <returns></returns>
        public string GetDisplayPath()
        {
            string         separator = SeparatorString;
            StringBuilder  sb        = new StringBuilder();
            BreadcrumbItem item      = RootItem;
            int            index     = 0;

            while (item != null)
            {
                if (sb.Length > 0)
                {
                    sb.Append(separator);
                }
                if (index >= BreadcrumbsToHide || item.SelectedItem == null)
                {
                    sb.Append(item.GetTracePathValue());
                }
                index++;
                item = item.SelectedBreadcrumb;
            }

            return(sb.ToString());
        }
 public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
 }
 private void HeaderPropertyChanged(BreadcrumbItem sender, AvaloniaPropertyChangedEventArgs e)
 {
     BreadcrumbItem item = sender as BreadcrumbItem;
 }
        private void SelectedBreadcrumbPropertyChanged(BreadcrumbItem sender, AvaloniaPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = sender as BreadcrumbItem;

            item.OnSelectedBreadcrumbChanged(e.OldValue, e.NewValue);
        }
        /// <summary>
        /// Occurs when the Overflow property is changed.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private void OverflowPropertyChanged(BreadcrumbItem o, AvaloniaPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = o as BreadcrumbItem;

            item.OnOverflowChanged((bool)e.NewValue);
        }
        /// <summary>
        ///  Appies the binding to the breadcrumb item.
        /// </summary>
        public void ApplyBinding()
        {
            object item = DataContext;

            if (item == null)
            {
                return;
            }

            BreadcrumbItem root     = this;
            IDataTemplate  template = HeaderTemplate;

            //DataTemplateSelector templateSelector = HeaderTemplateSelector;
            //if (templateSelector != null)
            //{
            //    template = templateSelector.SelectTemplate(item, root);
            //}
            if (template == null)
            {
                //DataTemplateKey key = GetResourceKey(item);
                //if (key != null)
                //{
                //    this.TryFindResource(key, template);
                //}
            }

            root.SelectedItem = null;

            TreeDataTemplate hdt = template as TreeDataTemplate;

            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.Bind(BreadcrumbItem.ItemsProperty, hdt.ItemsSource);
            }

            BreadcrumbBar bar = BreadcrumbBar;

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

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

            ApplyProperties(item);
        }
        /// <summary>
        /// Occurs when the Root property is changed.
        /// </summary>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        protected virtual void OnRootChanged(BreadcrumbBar bar, object oldValue, object newValue)
        {
            if (_isInitial == false)
            {
                newValue = GetFirstItem(newValue);
            }
            BreadcrumbItem oldRoot = oldValue as BreadcrumbItem;

            if (oldRoot != null)
            {
                oldRoot.IsRoot = false;
            }

            if (newValue == null)
            {
                RootItem = null;
                Path     = null;
            }
            else
            {
                BreadcrumbItem root = newValue as BreadcrumbItem;
                if (root == null)
                {
                    if (_isInitial == false)
                    {
                        root = BreadcrumbItem.CreateItem(newValue);
                    }
                    else
                    {
                        root = BreadcrumbItem.CreateInitialItem(newValue);
                    }
                }
                if (root != null)
                {
                    root.IsRoot = true;
                }
                if (oldValue != null)
                {
                    this.LogicalChildren.Remove((ILogical)oldValue);
                }
                RootItem = root;
                if (root != null)
                {
                    //bool result = LogicalTree.LogicalExtensions.GetLogicalParent(root as ILogical) == null;
                    ////if (LogicalTree.LogicalExtensions.GetLogicalParent(root as ILogical) == null)
                    //{
                    //    this.LogicalChildren.Remove(root);

                    //    this.LogicalChildren.Add(root);
                    //}
                }
                SelectedItem = root != null ? root.DataContext : null;
                if (IsInitialized)
                {
                    SelectedBreadcrumb = root;
                }
                else
                {
                    SelectedBreadcrumb = root;
                }
            }
        }
 /// <summary>
 /// Occurs when the selected item of an embedded BreadcrumbItem is changed.
 /// </summary>
 /// <param name="oldvalue"></param>
 /// <param name="newValue"></param>
 protected virtual void OnRootItemChanged(BreadcrumbItem oldValue, BreadcrumbItem newValue)
 {
 }
        /// <summary>
        /// Traces the specified path and builds the associated BreadcrumbItems.
        /// </summary>
        /// <param name="path">The traces separated by the SepearatorString property.</param>
        private bool BuildBreadcrumbsFromPath(string newPath)
        {
            PathConversionEventArgs e = new PathConversionEventArgs(ConversionMode.EditToDisplay, newPath, Root, PathConversionEvent);

            RaiseEvent(e);
            newPath = e.DisplayPath;

            BreadcrumbItem item = RootItem;

            if (item == null)
            {
                this.Path = null;
                return(false);
            }

            newPath = RemoveLastEmptySeparator(newPath);
            string[] traces = newPath.Split(new string[] { SeparatorString }, StringSplitOptions.RemoveEmptyEntries);
            if (traces.Length == 0)
            {
                RootItem.SelectedItem = null;
            }
            int index = 0;

            List <int> itemIndex = new List <int>();

            // if the root is specified as first trace, then skip:
            int length = traces.Length;
            int max    = BreadcrumbsToHide;

            if (traces.Length > index && max > 0 && traces[index] == (RootItem.TraceValue))
            {
                length--;
                index++;
                max--;
            }

            for (int i = index; i < traces.Length; i++)
            {
                if (item == null)
                {
                    break;
                }

                string trace = traces[i];
                OnPopulateItems(item);
                object next = item.GetTraceItem(trace);
                if (next == null)
                {
                    break;
                }
                itemIndex.Add(item.Items.OfType <object>().ToList().IndexOf(next));
                BreadcrumbItem container = item.ContainerFromItem(next);

                item = container;
            }
            if (length != itemIndex.Count)
            {
                //recover the last path:
                Path = GetDisplayPath();
                return(false);
            }

            // temporarily remove the SelectionChangedEvent handler to minimize processing of events while building the breadcrumb items:
            RemoveHandler(BreadcrumbItem.SelectionChangedEvent, breadcrumbItemSelectedItemChanged);
            try
            {
                item = RootItem;
                for (int i = 0; i < itemIndex.Count; i++)
                {
                    if (item == null)
                    {
                        break;
                    }
                    item.SelectedIndex = itemIndex[i];
                    item = item.SelectedBreadcrumb;
                }
                if (item != null)
                {
                    item.SelectedItem = null;
                }
                SelectedBreadcrumb = item;
                SelectedItem       = item != null ? item.Data : null;
            }
            finally
            {
                AddHandler(BreadcrumbItem.SelectionChangedEvent, breadcrumbItemSelectedItemChanged);
            }

            return(true);
        }
        /// <summary>
        /// Occurs before acessing the Items property of a BreadcrumbItem. This event can be used to populate the Items on demand.
        /// </summary>
        protected virtual void OnPopulateItems(BreadcrumbItem item)
        {
            BreadcrumbItemEventArgs args = new BreadcrumbItemEventArgs(item, BreadcrumbBar.PopulateItemsEvent);

            RaiseEvent(args);
        }
Esempio n. 26
0
 /// <summary>
 /// item which belongs to the breadcrumpitem
 /// </summary>
 /// <param name="item"></param>
 /// <param name="breadcrumb"></param>
 /// <param name="routedEvent"></param>
 public ApplyPropertiesEventArgs(object item, BreadcrumbItem breadcrumb, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item       = item;
     Breadcrumb = breadcrumb;
 }