Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DiagramNode.Resize() does not always work (Read 3264 times)
JasonB
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 24
Joined: Jun 5th, 2008
DiagramNode.Resize() does not always work
Jun 6th, 2008 at 9:01pm
Print Post  
To reproduce:

XAML:

<Window x:Class="WpfApplication2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:mindfusion="clr-namespace:MindFusion.Diagramming.Wpf;assembly=MindFusion.D
iagramming.Wpf"
 
    Title="Window1" Height="300" Width="300">
    <StackPanel>
       <mindfusion:Diagram x:Name="diagram" Behavior="DrawLinks" Bounds="0, 0, 1000, 1000" Background="White">

       </mindfusion:Diagram>
    </StackPanel>
</Window>

code :

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MindFusion.Diagramming.Wpf;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
       private TreeView tree;

       public Window1()
       {
           InitializeComponent();
           Test();
       }

       private void Test()
       {
           tree = new TreeView();
           TreeViewItem item = new TreeViewItem();
           TreeViewItem item1 = new TreeViewItem();
           TreeViewItem item2 = new TreeViewItem();

           item.Header = "sdsfdsdfdsfdsffdfdfdsfsdffsf";
           item1.Header = "2342sdfffsfdsfdsf34";
           item2.Header = "23sdfsdf42sdfdsdsdfsdfsfs34";

           item.Items.Add(item1);
           item.Items.Add(item2);
           tree.Items.Add(item);

           item.Expanded += new RoutedEventHandler(item_Expanded);
           diagram.Nodes.Add(tree);
           DiagramNode node = (DiagramNode)Diagram.GetDiagramItem(tree);
           Rect bounds = new Rect(50, 50, 30, 30);
           node.Bounds = bounds;
       }

       void item_Expanded(object sender, RoutedEventArgs e)
       {

           DiagramNode node = (DiagramNode)Diagram.GetDiagramItem(tree);
           node.Resize(node.Bounds.Width + 10, node.Bounds.Height + 10);
       }
    }
}



Occasionally the node will expand, and then immediately reduce to the old size. Keep collapsing / expanding the top level item. Some times it expands as expected, some times it expands and then jumps right back to the old size.

I noticed also DiagramNodeAdapter doesn't seem to be respecting DesiredSize (always set to 1?) and thus not properly participating in the WPF layout system, which is probably related to this.

Seems like the size of the node should be set to the size of its content, like any panel would do, instead of cutting it off. I'd rather not set node.bounds at all and just have it set to size of content.

Also I'd like to subclass DiagramNodeAdapter to perhaps properly participate in the layout myself, but can't seem to see where to set the UIElement. Seems like this is an internal method only? Can that be changed?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DiagramNode.Resize() does not always work
Reply #1 - Jun 7th, 2008 at 1:18pm
Print Post  
Actually the problem happens because upon MouseDown the Diagram starts a drag operation for the TreeView, and cancels it upon MouseUp if the mouse hasn't moved at least a couple of pixels. Cancelling the drag operation involves restoring the original position of the node, which causes the jump-back effect.

It seems most of the time the TreeView's Expanded event is raised after the drag operation is cancelled, and then Bounds is set correctly. But sometimes Expanded comes before the MouseUp / drag-cancellation, the handler sets Bounds correctly, but then the diagram's MouseUp code restores the original bounds. I don't know why Expanded is not is not raised consistently either only before or only after MouseUp - perhaps the TreeView processes item expansion asynchronously.

For the 1.0.1 release we'll try to implement a better way to coordinate the mouse input between the diagram and hosted controls. Until then, you could set a HandlesStyle that won't start a drag operation when the mouse is inside the TreeView, for example SquareHandles:

...
DiagramNode node = (DiagramNode)Diagram.GetDiagramItem(tree);
node.HandlesStyle = HandlesStyle.SquareHandles;
...

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


I love YaBB 1G - SP1!

Posts: 24
Joined: Jun 5th, 2008
Re: DiagramNode.Resize() does not always work
Reply #2 - Jun 9th, 2008 at 12:56am
Print Post  
Thanks Stoyan. This does fix the issue but of course now the nodes cannot be moved (the treeview is the entire node), which is going to be a showstopper for us. Any idea when the 1.0.1 release is going to happen?

Thanks for all of your help with our issues.

Jason
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DiagramNode.Resize() does not always work
Reply #3 - Jun 9th, 2008 at 7:19am
Print Post  
You can still move a TreeView be dragging the selection handle drawn in the center of a node. Instead of SquareHandles, you might use the HatchHandles style, which lets you move a node from any point on the border, but does not intercept the mouse input when the pointer is inside the node. You could also try the Custom HandlesStyle, which lets you do your own hit-testing from the HitTestAdjustmentHandles event handler.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint