/// <summary> /// Creates a model to represent a control in the toolbox. /// </summary> /// <param name="controlData">The data of the control to be modeled.</param> /// <returns>Returns a new instance of the model for the control.</returns> private ControlTreeNodeModel CreateControlModel(ControlData controlData) { var controlModel = new ControlTreeNodeModel(controlData); controlModels[controlData.FullName] = controlModel; return(controlModel); }
/// <summary> /// This method is called when a drag operation completes by dropping over the simulated designer surface. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args.</param> private void OnDesignerDrop(object sender, DragEventArgs e) { // Lookup the dropped control (only a single item is supported) ControlTreeNodeModel controlModel = CustomTreeListBoxItemAdapter .GetDraggedModels(e.Data, treeListBox) .OfType <ControlTreeNodeModel>() .FirstOrDefault(); // Here is where the dropped item would be processed. For this demo, only a message will be displayed. if (controlModel is null) { MessageBox.Show($"The dropped item is not supported by this designer.", "UI Designer", MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show($"Add the following control to the designer:\r\n\r\n\t{controlModel.FullName}", "UI Designer", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// Tries to get the category and control models for the specified item. /// </summary> /// <param name="toolboxControl">The <see cref="TreeListBox"/> control.</param> /// <param name="item">The item to examine.</param> /// <param name="categoryModel">The resulting <see cref="CategoryTreeNodeModel"/>.</param> /// <param name="controlModel">The resulting <see cref="ControlTreeNodeModel"/>.</param> /// <returns> /// <c>true</c> if results were found; otherwise, <c>false</c>. /// </returns> private bool TryGetModelsFromItem(TreeListBox toolboxControl, object item, out CategoryTreeNodeModel categoryModel, out ControlTreeNodeModel controlModel) { if (item is ControlTreeNodeModel localControlModel) { controlModel = localControlModel; return(TryGetCategory(toolboxControl, controlModel, out categoryModel)); } else if (item is EmptyPlaceholderTreeNodeModel emptyPlaceholderModel) { controlModel = null; return(TryGetCategory(toolboxControl, emptyPlaceholderModel, out categoryModel)); } else if (item is CategoryTreeNodeModel localCategoryModel) { controlModel = null; categoryModel = localCategoryModel; return(true); } categoryModel = null; controlModel = null; return(false); }