/// <summary> /// Gets the edit path from the tracess of the BreacrumbItems. /// </summary> /// <returns></returns> public string GetEditPath() { string displayPath = GetDisplayPath(); PathConversionEventArgs e = new PathConversionEventArgs(ConversionMode.DisplayToEdit, displayPath, Root, PathConversionEvent); RaiseEvent(e); return(e.EditPath); }
/// <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> /// 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); }