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); }
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.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; }
/// <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); }
/// <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); }
/// <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 ApplyPropertiesEventArgs(object item, BreadcrumbItem breadcrumb, RoutedEvent routedEvent) : base(routedEvent) { Item = item; Breadcrumb = breadcrumb; }
public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent) : base(routedEvent) { Item = item; }
/// <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); }
/// <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); }
/// <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(); }
protected override DependencyObject GetContainerForItemOverride() { BreadcrumbItem item = new BreadcrumbItem(); return(item); }
private static void SelectedBreadcrumbPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { BreadcrumbItem item = d as BreadcrumbItem; item.OnSelectedBreadcrumbChanged(e.OldValue, e.NewValue); }
private static void HeaderPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { BreadcrumbItem item = sender as BreadcrumbItem; }