Наследование: System.Windows.Controls.Primitives.Selector
Пример #1
0
        /// <summary>
        /// Populate the Items of the specified BreadcrumbItem with the sub folders if necassary.
        /// </summary>
        /// <param name="item"></param>
        private static void PopulateFolders(BreadcrumbItem item)
        {
            BreadcrumbBar bar = item.BreadcrumbBar;
            string path = bar.PathFromBreadcrumbItem(item);
            string trace = item.TraceValue;
            if (trace.Equals("Computer"))
            {
                string[] dirs = System.IO.Directory.GetLogicalDrives();
                foreach (string s in dirs)
                {
                    string dir = s;
                    if (s.EndsWith(bar.SeparatorString)) dir = s.Remove(s.Length - bar.SeparatorString.Length, bar.SeparatorString.Length);
                    FolderItem fi = new FolderItem();
                    fi.Folder = dir;

                    item.Items.Add(fi);
                }
            }
            else
            {
                try
                {
                    string[] paths = System.IO.Directory.GetDirectories(path + "\\");
                    foreach (string s in paths)
                    {
                        string file = System.IO.Path.GetFileName(s);
                        FolderItem fi = new FolderItem();
                        fi.Folder = file;
                        item.Items.Add(fi);
                    }
                }
                catch { }
            }
        }
Пример #2
0
 /// <summary>
 /// Gets a list of FolderItems that are the subfolders of the specified BreadcrumbItem.
 /// </summary>
 private static List<FolderItem> GetFolderItemsFromBreadcrumb(BreadcrumbItem item)
 {
     BreadcrumbBar bar = item.BreadcrumbBar;
     string path = bar.PathFromBreadcrumbItem(item);
     string trace = item.TraceValue;
     string[] subFolders;
     if (trace.Equals("Computer"))
     {
         subFolders = GetDrives(bar.SeparatorString).ToArray();
     }
     else
     {
         try
         {
             subFolders = (from dir in System.IO.Directory.GetDirectories(path + "\\") select System.IO.Path.GetFileName(dir)).ToArray();
         }
         catch
         {
             //maybe we don't have access!
             subFolders = new string[] { };
         }
     }
     List<FolderItem> folderItems = (from folder in subFolders orderby folder select new FolderItem { Folder = folder }).ToList();
     return folderItems;
 }
Пример #3
0
        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);
        }
Пример #4
0
        //TODO: Menu needs too long to render if there are too many items (> 20000).
        void contextMenu_Opened(object sender, RoutedEventArgs e)
        {
            contextMenu.Items.Clear();
            contextMenu.ItemTemplate         = ItemTemplate;
            contextMenu.ItemTemplateSelector = ItemTemplateSelector;

            //    List<MenuItem> menuItems = new List<MenuItem>();
            foreach (object item in Items)
            {
                if (!(item is MenuItem) && !(item is Separator))
                {
                    RibbonMenuItem menuItem = new RibbonMenuItem();
                    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;
        }
Пример #5
0
        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);
            //if (args.OriginalSource == item.BreadcrumbBar.RootItem) {
            //	item.BreadcrumbBar.BuildBreadcrumbsFromPath(item.BreadcrumbBar.GetDisplayPath());
            //}
        }
Пример #6
0
        /// <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);
        }
Пример #7
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);
        }
Пример #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 (bcItem != null)
         {
             ApplyProperties(item);
             string value = bcItem.TraceValue;
             if (value != null && value.Equals(trace, StringComparison.InvariantCultureIgnoreCase))
             {
                 return(item);
             }
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Пример #9
0
 protected override DependencyObject GetContainerForItemOverride()
 {
     BreadcrumbItem item = new BreadcrumbItem();
     return item;
 }
Пример #10
0
        /// <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();
        }
Пример #11
0
        /// <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);
        }
Пример #12
0
        private static void SelectedBreadcrumbPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnSelectedBreadcrumbChanged(e.OldValue, e.NewValue);
        }
Пример #13
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            BreadcrumbItem item = new BreadcrumbItem();

            return(item);
        }
Пример #14
0
 public ApplyPropertiesEventArgs(object item, BreadcrumbItem breadcrumb, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item       = item;
     Breadcrumb = breadcrumb;
 }
Пример #15
0
 /// <summary>
 /// Populate the Items of the specified BreadcrumbItem with the sub folders if necassary.
 /// </summary>
 /// <param name="item"></param>
 private static void PopulateFolders(BreadcrumbItem item)
 {
     List<FolderItem> folderItems = GetFolderItemsFromBreadcrumb(item);
     item.ItemsSource = folderItems;
 }
Пример #16
0
 /// <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);
 }
Пример #17
0
 private static void HeaderPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
 {
     BreadcrumbItem item = sender as BreadcrumbItem;
 }
 public ApplyPropertiesEventArgs(object item, BreadcrumbItem breadcrumb, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
     Breadcrumb = breadcrumb;
 }
Пример #19
0
 protected virtual void OnRootItemChanged(BreadcrumbItem oldValue, BreadcrumbItem newValue)
 {
 }
Пример #20
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);
        }
Пример #21
0
 /// <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;
 }
 public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
 }
 public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
 }
Пример #24
0
        /// <summary>
        /// Occurs when the Root property is changed.
        /// </summary>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        public virtual void OnRootChanged(object oldValue, object newValue)
        {
            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)
                {
                    root = BreadcrumbItem.CreateItem(newValue);
                }
                if (root != null)
                {
                    root.IsRoot = true;
                }
                this.RemoveLogicalChild(oldValue);
                RootItem = root;
                if (root != null)
                {
                    if (LogicalTreeHelper.GetParent(root) == null) this.AddLogicalChild(root);
                }
                SelectedItem = root != null ? root.DataContext : null;
                if (IsInitialized) SelectedBreadcrumb = root; else selectedBreadcrumb = root;
            }
        }
Пример #25
0
 /// <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(PathConversionEventArgs.ConversionMode.DisplayToEdit, sb.ToString(), Root, PathConversionEvent);
     RaiseEvent(e);
     return e.EditPath;
 }
Пример #26
0
 /// <summary>
 /// Update the list of Subfolders from a BreadcrumbItem.
 /// </summary>
 private void UpdateFolderItems(BreadcrumbItem item)
 {
     List<FolderItem> actualFolders = GetFolderItemsFromBreadcrumb(item);
     List<FolderItem> currentFolders = item.ItemsSource as List<FolderItem>;
     currentFolders.Clear();
     currentFolders.AddRange(actualFolders);
 }