This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, Is there a way to add tools dynamically to the toolbox in code? Or at the very least hide and show them when needed? Or perhaps a way to expand and collapse sections with code? Thanks! |
|
|
Hello, Here is a very simple example of adding a tool to a toolbox in code:
The first line is grabbing a DiagramNodeTool (which I've called NodeTool) that I've set up in the ResourceDictionary (which I've called rd) of the main window . An alternative to this is to build DiagramNodeTools in code, but since it is a control, it's easier to create in xaml. The next 2 lines simple create a collection containing that one tool. If you will be adding or removing tools a lot, you may want to keep the collections around as a field, or a property on a model so that you can manipulate them. The last line sets the ItemsSource of a ToolBoxGroup in xaml (which I've called ToolGroup) to be the collection containing a tool. This could also be done as a binding in xaml to a collection property on a model. An alternative to this approach would be to hide individual tools when they're not needed. This could be done by binding to the Visibility property of each tool. Preferably, use a boolean-to-visibility converter so that your model can expose booleans instead of Visibility values. Setting the visibility of a tool to Collapsed will cause it to disappear. Of course multiple tools could bind to the same boolean model property if the logic for showing/hiding them are the same. Showing/hiding tools has the advantage of being more MVVM. A downside is that the performance could be impacted if you have a very large number of tools. The groups can be expanded and collapsed in code by binding the IsExpanded property of each DiagramToolBoxGroup to boolean properties on the model. Let me know if you have further questions about any of this. -Jason Fauchelle |
|