/// <summary> /// Create the style for breadcrumb items. /// </summary> private Style CreateBreadcrumbItemStyle(FolderIconConverter imageConverter) { Style breadcrumbItemStyle = CreateCommonBreadcrumbItemStyle(imageConverter); Setter itemsSource = new Setter() { Property = BreadcrumbItem.ItemsSourceProperty, Value = new Binding("Children") }; breadcrumbItemStyle.Setters.Add(itemsSource); return(breadcrumbItemStyle); }
/// <summary> /// Create the base style for the all breadcrumb items. /// </summary> private Style CreateCommonBreadcrumbItemStyle(FolderIconConverter imageConverter) { Style breadcrumbItemStyle = new Style() { TargetType = typeof(BreadcrumbItem) }; Setter imageSource = new Setter() { Property = BreadcrumbItem.ImageSourceProperty, Value = new Binding("Entity.ImageData") { Converter = imageConverter } }; breadcrumbItemStyle.Setters.Add(imageSource); return(breadcrumbItemStyle); }
/// <summary> /// Initializes an instance of the <c>FolderNavBar</c> class. /// </summary> public FolderNavBar() { PopupButton popupButton = new PopupButton() { DisplayMode = PopupButtonDisplayMode.ButtonOnly, IsRounded = false, IsTransparencyModeEnabled = true }; Image refresh = new Image() { Source = new BitmapImage(new Uri("Resources/Refresh16.png", UriKind.Relative)), Stretch = Stretch.None, VerticalAlignment = System.Windows.VerticalAlignment.Center }; MultiBinding tooltip = new MultiBinding() { Converter = new StringFormatConverter(), ConverterParameter = "{}Refresh {0}" }; PathConverter pathConverter = new PathConverter(); FolderIconConverter imageConverter = new FolderIconConverter(); FolderMenuIconConverter imageMenuConverter = new FolderMenuIconConverter(); this.breadcrumb = new Breadcrumb(); this.breadcrumb.Margin = new Thickness(0); this.breadcrumb.MenuVerticalOffset = -2; this.breadcrumb.AutoMinimizeItemCount = 0; this.breadcrumb.ConvertItem += OnBreadcrumbConvertItem; this.breadcrumb.ImageMinWidth = 16; this.breadcrumb.SetBinding(Breadcrumb.RootItemProperty, new Binding() { Source = this, Path = new PropertyPath("RootNode") }); this.breadcrumb.ItemContainerStyle = CreateRootBreadcrumbItemStyle(imageConverter); this.breadcrumb.ItemTemplate = CreateBreadcrumbItemTemplate(); this.breadcrumb.MenuItemTemplate = CreateMenuItemNormalTemplate(); this.breadcrumb.MenuItemContainerStyle = CreateMenuItemContainerStyle(imageMenuConverter); this.breadcrumb.MenuItemExpandedTemplate = CreateMenuItemExpandedTemplate(); this.breadcrumb.ComboBoxItemTemplate = CreateComboBoxItemTemplate(pathConverter); this.breadcrumb.SetBinding(Control.BackgroundProperty, new Binding("Background") { Source = this, Mode = BindingMode.TwoWay }); this.breadcrumb.SetBinding(Control.BorderThicknessProperty, new Binding("BorderThickness") { Source = this, Mode = BindingMode.TwoWay }); this.breadcrumb.SetBinding(Control.BorderBrushProperty, new Binding("BorderBrush") { Source = this, Mode = BindingMode.TwoWay }); tooltip.Bindings.Add(new Binding() { Source = this.breadcrumb, Path = new PropertyPath("SelectedItem.Entity.Name"), Mode = BindingMode.OneWay }); popupButton.Content = refresh; this.breadcrumb.ActionButtons.Add(popupButton); this.Content = this.breadcrumb; this.history = new ObservableCollection <FolderNavNode>(); this.breadcrumb.ComboBoxItemsSource = history; this.breadcrumb.SelectedItemChanged += OnSelectedItemChanged; this.SetBinding(FolderNavBar.IsEditingProperty, new Binding("IsEditing") { Source = this.breadcrumb }); if (pathConverter != null) { pathConverter.SetBinding(PathConverter.RootProperty, new Binding("RootNode") { Source = this, Mode = BindingMode.OneWay }); } }