private void PopulateToolbox() { var itemsSource = new HierarchicalGalleryItemsCollection(); var containerGallerty = itemsSource.LastOrDefault(); if (containerGallerty != null) { containerGallerty.Items.Add(new GalleryItem("Horizontal Main Shape", new HorizontalMainContainerShape())); containerGallerty.Items.Add(new GalleryItem("Vertical Main Shape", new VerticalMainContainerShape())); containerGallerty.Items.Add(new GalleryItem("Horizontal Swimlane", new HorizontalSwimlaneShape())); containerGallerty.Items.Add(new GalleryItem("Vertical Swimlane", new VerticalSwimlaneShape())); } this.toolBox.ItemsSource = itemsSource; }
private void InitializeToolBox() { HierarchicalGalleryItemsCollection galleries = new HierarchicalGalleryItemsCollection(); foreach (string key in glyphGalleries.Keys) { sortedGallleries[key] = new ObservableCollection <GalleryItem>(); } // Fake Galleries with no items, it serves for label only. galleries.Insert(0, new Gallery() { Header = "SHAPES" }); galleries.Add(new Gallery() { Header = "GLYPHS" }); ResourceDictionary dict = new ResourceDictionary(); dict.Source = new System.Uri("/Telerik.Windows.Controls;component/Themes/FontResources.xaml", System.UriKind.RelativeOrAbsolute); ObservableCollection <GlyphInfo> glyphs = new ObservableCollection <GlyphInfo>(); int i = 0; foreach (var item in dict.Keys) { if (!item.ToString().StartsWith("Glyph")) { continue; } GalleryItem galleryItem = new GalleryItem() { ItemType = "Glyph" }; galleryItem.Header = SplitString(item.ToString()); GlyphInfo glyph = new GlyphInfo() { GlyphName = galleryItem.Header, GlyphContent = dict[item] }; byte[] bytes = System.Text.Encoding.Unicode.GetBytes(glyph.GlyphContent.ToString()); string categoryCode = bytes[1].ToString("x2"); //returns e0 e1 ... e9 string categoryCode2 = bytes[0].ToString("x2"); glyph.Category = glyphGalleries[categoryCode].Header.Trim(); glyphs.Add(glyph); // Gallery item has no Tag property so we will use the shapes' one. We will sort the gallery items by the this tag (hex of the glyph). galleryItem.Shape = new RadDiagramTextShape() { Content = dict[item], Tag = categoryCode + categoryCode2 }; allGlyphs[i++] = glyph; sortedGallleries[categoryCode].Add(galleryItem); } foreach (string key in sortedGallleries.Keys) { foreach (GalleryItem item in sortedGallleries[key].OrderBy(x => x.Shape.Tag.ToString())) { this.glyphGalleries[key].Items.Add(item); } galleries.Add(this.glyphGalleries[key]); } this.toolbox.ItemsSource = galleries; this.autoComplete.ItemsSource = glyphs; }