Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram component resizing (Read 3085 times)
PetrOs
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: May 26th, 2011
Diagram component resizing
Dec 7th, 2011 at 8:47am
Print Post  
Hey

In my project, I have a subclass of a diagram class. I add it inside of a grid row in XAML. As I want my component's bounds to adjust to exact component size, i tried to attach a listener to a Diagram's SizeChanged event. However, I get this event exactly once, when the size changes from 0,0,0,0 to some reasonable value on startup. No events are produced when my window is resized later. Any idea?

My XAML code looks like this:
[code]
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="16" />
</Grid.ColumnDefinitions>
<BoundDiagram:BoundDiagram DataItems="{Binding Path=VisibleElements}" Grid.Column="0" />
</Grid>
[/code]

And inside the BoundDiagram's constructor
[code]
SizeChanged += new SizeChangedEventHandler(DiagramSizeChanged);
[/code]
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram component resizing
Reply #1 - Dec 7th, 2011 at 9:16am
Print Post  
Hi,

Try handling BoundsChanged instead, and set Diagram.AutoResize to a value different than None.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PetrOs
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: May 26th, 2011
Re: Diagram component resizing
Reply #2 - Dec 7th, 2011 at 1:40pm
Print Post  
Tried, no effect.. (
Autoresize="AllDirections" in XAML

BoundsChanged += new EventHandler(DiagramBoundsChanged); in constructor
)

I get only one stop on the event handler breakpoint, when my window is coming up.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram component resizing
Reply #3 - Dec 8th, 2011 at 7:33am
Print Post  
Perhaps you should set Width="Auto" instead of * if you expect the grid column to resize itself to fit the diagram. Otherwise the grid assigns all available width to the column. Having other non-auto-sizing panel inside the grid as a parent of the diagram will prevent the column from resizing too, e.g. if you use a ScrollViewer or Ruler that allocates all space the diagram requests by means of a scrollable area.

Also you should have in mind that AutoResize changes Diagram.Bounds only when adding new nodes or modifying nodes interactively. If you are setting node.Bounds from the code behind or applying some layout algorithm, you should explicitly call Diagram.ResizeToFitItems afterwards.

You can find a small test project here:
https://mindfusion.eu/_samples/wpfdiag_AutoResize.zip

Click the add node button several times to add new nodes and the column that contains the diagram should resize to fit them. Click the arrange button to run a layout algorithm and set a different Bounds by calling ResizeToFitItems. Note that the BoundsChanged handler does nothing apart from logging the new value - the diagram sets the Bounds size as its DesiredSize anyway and the parent panel should honor it on the next wpf layout pass as long as the panel supports auto-sizing content.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PetrOs
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: May 26th, 2011
Re: Diagram component resizing
Reply #4 - Dec 8th, 2011 at 11:23am
Print Post  
Width="*" had the effect, that a combined scroll/marker bar on the right screen size detached and moved around.

The effect I want is that the diagram bounds are exactly equal to the visible area. My layouting algorithm takes the visible size, and tries to place all things that fit into it, hiding all non-necessary stuff, and resizing some global elements...

I found a kind of a solution that works, but which is ugly to be honest. I wrapped the BoundDiagram into a ContentControl, added an event handler for the resize of that ContentControl in the xaml.cs code behind, and that code does nothing except setting the diagram's renderSize to the ContentControl render size.

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint