private void AddContent(string uriString) { MdiDemoContent newContent = null; switch (uriString) { case "MdiWindow": newContent = new MdiDemoContent() { Title = "Empty" }; break; case "Small": newContent = new MdiDemoColorGridContent() { Title = "Small Grid", NumberOfCells = 100 }; break; case "Medium": newContent = new MdiDemoColorGridContent() { Title = "Medium Grid", NumberOfCells = 1000 }; break; case "Large": newContent = new MdiDemoColorGridContent() { Title = "Large Grid", NumberOfCells = 10000 }; break; default: newContent = new MdiDemoPageContent() { Title = uriString, Uri = new Uri(uriString, UriKind.Relative) }; break; } if (!(new Rect(MainMdiView.RenderSize).Contains(_nextNewContentPosition))) { _nextNewContentPosition = new Point(0, 0); } newContent.WindowRect = new Rect(_nextNewContentPosition, new Size(300, 200)); _nextNewContentPosition.Offset(20, 20); Workspace.Content.Add(newContent); }
/// <summary> /// Execute handler for the MdiCommands.CloseWindow command. /// </summary> /// <remarks> /// The command is only enabled if the MdiWindow instance is one /// of the containers generated for one of the MdiDemoContent /// instances in Worspace.Content. When the command is executed, /// the item is removed from the Workspace.Content collection. /// </remarks> private void CloseWindow_Execute(object sender, ExecutedRoutedEventArgs e) { MdiWindow window = MainMdiView.ContainerFromElement((DependencyObject)e.OriginalSource); if (window != null) { MdiDemoContent item = MainMdiView.ItemContainerGenerator.ItemFromContainer(window) as MdiDemoContent; if (item != null && Workspace.Content.Contains(item)) { Workspace.Content.Remove(item); } } }