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
|
I'd like to dynamically set (or preferably databind) the size of a node to the actual size of its content. This is useful in 2 key scenarios: 1) I want to have the node size be reasonable when the content is of different sizes 2) I'd like to have expanders inside the nodes. When I expand the contents, I want the node itself to get bigger. Is there a simple way to do this, or am I going to have to hack the visual tree? Thanks, -Scott |
|
|
This question is becoming urgent for us. I was wondering if you might have the chance to respond?
Thanks, -Scott |
|
|
We're actively investigating it, but we don't yet have a definite answer for you. We will probably not be able to do the expand/collapse stuff in the short term, but on the size to content front we are looking at ways to surface size changes (probably as an event) so that you can resize the node at the model level. Jason is working in this right now. |
|
|
Hello Scott After experimenting with this for a while, I came up with 2 possible ways to do this: 1/ <Expander Expanded="Expander_Changed" Collapsed="Expander_Changed" Tag="{Binding}" > Then in the code behind for Expanded_Changed, we cast the 'sender' parameter into an expander, and then cast the Tag property value of that expander to be an IDiagramNode. Now we can freely set the bounds of the node to be related to the ActualWidth and ActualHeight of the expander. Here is an example (ignoring error checking): private void Expander_Changed(object sender, RoutedEventArgs e) Here, when the expander is expanded, I'm just setting the width of the node to be 100, and setting the height to be the ActualHeight of the expander plus some margin. When it is collapsed we can set it to be some constant collapsed size. ADVANTAGES: 2/ <TextBox Text="{Binding Data}" ms:DiagramNodeElement.RaisesBoundsChangeRequested="True" .... /> Then, somewhere in the code behind for a window that holds the DiagramSurface, we can write: ds.AddHandler(DiagramNodeElement.BoundsChangeRequestedEvent, new EventHandler<BoundsChangeRequestedEventArgs>(OnBoundsChangeRequested)); So now whenever the size of the TextBox changes such as when the text changes, the OnBoundsChangeRequested method which we would also place in the code behind will be called. For example: private void OnBoundsChangeRequested(object sender, BoundsChangeRequestedEventArgs e) Now the size of the node will dynamically be updated whenever the user changes the text. ADVANTAGES: In both of these examples, we can also easily add maximum limits to how big a node can become. The attached property and event on DiagramNodeElement will be available in the next nightly build. Regards |
|