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?