private NTreeViewItem CreateTreeViewItem(NXmlElement element) { if (IsSingleExampleTile(element)) { // This is a tile with a single example, so create only the example tree view item return(CreateTreeViewItem((NXmlElement)element.GetChildAt(0))); } NImage icon; string name = element.GetAttributeValue("name"); if (String.IsNullOrEmpty(name)) { return(null); } switch (element.Name) { case "tile": case "group": case "folder": icon = NResources.Image__16x16_Folders_png; break; case "example": icon = NResources.Image__16x16_Contacts_png; break; default: return(null); } NExampleTile tile = new NExampleTile(icon, name); tile.Status = element.GetAttributeValue("status"); tile.Box2.VerticalPlacement = ENVerticalPlacement.Center; tile.Spacing = NDesign.HorizontalSpacing; NTreeViewItem item = new NTreeViewItem(tile); if (element.Name == "example") { // This is an example element item.Tag = element; if (NApplication.Platform == ENPlatform.Silverlight) { // Handle the right click event in Silverlight to show a context menu // for copying a link to the example item.MouseDown += OnTreeViewItemMouseDown; } } return(item); }
protected override void OnMouseUp(NMouseButtonEventArgs args) { base.OnMouseUp(args); if (args.Cancel || args.Button != ENMouseButtons.Left) { return; } if (args.TargetNode is NImageBox && args.TargetNode.Tag is NXmlElement) { OnExampleCategoryMouseUp(args); return; } // Get the clicked example tile NExampleTile tile = args.TargetNode as NExampleTile; if (tile == null) { tile = (NExampleTile)args.TargetNode.GetFirstAncestor(NExampleTile.NExampleTileSchema); } if (tile == null) { return; } NItemInfo itemInfo = (NItemInfo)tile.Tag; if (TileSelected != null) { TileSelected(itemInfo.XmlElement); } // Mark the event as handled args.Cancel = true; }
/// <summary> /// Creates a tile. Tile elements can contain only examples. /// </summary> /// <param name="element"></param> /// <param name="categoryNamespace"></param> /// <returns></returns> private NWidget CreateTile(NXmlElement element, string categoryNamespace) { string tileTitle = element.GetAttributeValue("name"); string iconName = element.GetAttributeValue("icon"); // Get the icon for the tile NImage icon = null; if (iconName != null) { if (NApplication.IOService.DirectorySeparatorChar != '\\') { iconName = iconName.Replace('\\', NApplication.IOService.DirectorySeparatorChar); } string imageFolder = NPath.GetFullDirectoryName(iconName); if (String.IsNullOrEmpty(imageFolder)) { // The icon is in the folder for the current category imageFolder = categoryNamespace; } else { // The icon is in a folder of another category imageFolder = NPath.Normalize(NPath.Combine(categoryNamespace, imageFolder)); if (imageFolder[imageFolder.Length - 1] == NApplication.IOService.DirectorySeparatorChar) { imageFolder = imageFolder.Remove(imageFolder.Length - 1); } // Update the icon name iconName = NPath.GetFileName(iconName); } iconName = "RIMG_ExampleIcons_" + imageFolder + "_" + iconName.Replace('.', '_'); icon = new NImage(new NEmbeddedResourceRef(NResources.Instance, iconName)); } // Create and configure the tile NExampleTile tile = new NExampleTile(icon, tileTitle); tile.HorizontalPlacement = ENHorizontalPlacement.Left; tile.Status = element.GetAttributeValue("status"); tile.Tag = new NItemInfo(element); // Add the examples of the current tile to the examples map INIterator <NXmlNode> iter = element.GetChildNodesIterator(); while (iter.MoveNext()) { NXmlElement exampleElement = iter.Current as NXmlElement; if (exampleElement == null) { continue; } string examplePath = GetExamplePath(exampleElement); if (icon != null) { icon = new NImage(icon.ImageSource); } NExampleTile example = new NExampleTile(icon, examplePath); example.Status = exampleElement.GetAttributeValue("status"); example.Tag = new NItemInfo(exampleElement); if (m_ExamplesMap.Contains(examplePath) == false) { m_ExamplesMap.Add(examplePath, example); } } return(tile); }