i found the problem:
when i use the overview
this.Loaded += (s, e) => { myOverview.Observed = myDiagram; };
its doing the behavior i specified (children nodes are not rearrange).
when i remove it - all works as accepted.
i made an example, and its doing the same:
can you help?
*******************************************************
cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Globalization;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Northwoods.GoXam;
using Northwoods.GoXam.Model;
using Northwoods.GoXam.Layout;
using Northwoods.GoXam.Tool;
using System.Xml.Linq;
using System.Runtime.InteropServices;
using System.Collections.ObjectModel;
namespace TestGoExam
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
LoadFile(“c:\TestGoExam.xml”); // file below
/*
var model = new TreeModel<MyInfo, String>();
model.NodeKeyPath = “Name”;
model.ParentNodePath = “Parent”;
// Create all of the node data that we might show.
var nodes = new List() {
new MyInfo() { Key = “Root” }, // the root node
// intermediate nodes: decisions on personality characteristics
new MyInfo() { Key = “I”,Name=“i”,Parent=null },
new MyInfo() { Key = “E”,Name=“e” ,Parent=“i”},
new MyInfo() { Key = “IN” ,Name=“in”},
new MyInfo() { Key = “IS” ,Name=“is”},
new MyInfo() { Key = “EN” ,Name=“en”},
new MyInfo() { Key = “ES” ,Name=“es”},
};
model.NodesSource = nodes;
// Use the Key of each Info to construct the proper link data from the parent Info.
// In a different application such programmatic construction of the links might not be possible.
// But in this application, the relationships can be determined by splitting up the Key string.
var links = new List();
foreach (MyInfo info in nodes)
{
String key = info.Key;
if (key == “Root”) continue;
if (key.Length == 0) continue;
// e.g., if key==“INTJ”, we want: prefix=“INT” and letter=“J”
String prefix = key.Substring(0, key.Length - 1);
String letter = key[key.Length - 1].ToString();
if (prefix.Length == 0) prefix = “Root”;
// e.g., connect node “INT” with port “J” to node “INTJ” with the whole node as the port
//links.Add(new UniversalLinkData(prefix, letter, key, null));
//model.AddLink(info,);
}
//model.AddLink() = links;
myDiagram.Model = model;
*
/
}
public void LoadFile(string path)
{
var model = new TreeModel<MyInfo, String>();
model.NodeKeyPath = “Text”;
model.ParentNodePath = “Parent”;
// load the XML data from a file that is an embedded resource
using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(stream))
{
XElement root = XElement.Load(reader);
// iterate over all the nested elements inside the root element
// collect a new Info() for each XElement, remembering the interesting attribute values
// need to call ToList() to avoid recomputation of deferred Linq Select operation
model.NodesSource = root.Descendants().OfType().Select(x => new MyInfo(x)).ToList();
model.Modifiable = true;
myDiagram.Model = model;
this.Loaded += (s, e) => { myOverview.Observed = myDiagram; };
}
}
}
public class MyInfo : TreeModelNodeData
{
public MyInfo(String text)
{
this.Text = text;
this.LayoutId = “All”;
}
public MyInfo(XElement x) {
XAttribute a;
a = x.Attribute(“text”);
if (a != null) this.Text = a.Value; else this.Text = “”;
a = x.Attribute(“color”);
if (a != null) this.Color = a.Value; else this.Color = “Transparent”;
// see if this is not the root node
XElement parent = x.Parent;
if (parent != null && parent.Name == “node”) {
a = parent.Attribute(“text”); // get the parent node’s text, assumed to be unique
if (a != null) this.Parent = a.Value;
this.LayoutId = Dir(x); // laid out by the TreeLayout identified by the direction
} else {
this.LayoutId = “All”; // the root node participates in all layouts
}
}
// recurse up the XElement tree to find a with a “dir” attribute
private String Dir(XElement x)
{
if (x != null && x.Name == “node”)
{
// if it has a “dir” attribute, return its value
XAttribute a = x.Attribute(“dir”);
if (a != null) return a.Value;
}
// try going up the parent chain
if (x.Parent != null) return Dir(x.Parent);
return “Right”; // unknown direction: default towards the right
}
// the model is assumed to be static,
// so these properties don’t need to raise a PropertyChanged event in their setters
public String Text { get; set; }
public String Color { get; set; }
public String LayoutId { get; set; }
public String Parent { get; set; }
}
private void myDiagram_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Northwoods.GoXam.Node node = myDiagram.SelectedNode;
node.Diagram.StartTransaction(“myDiagram_MouseDoubleClick”);
var parentdata = node.Data as MyInfo;
for (int i = 0; i < 3; i++)
{
var n = new MyInfo(“testing”);
n.Parent = “leaf1”;
n.Location = node.Location;
node.Model.AddNode(n); // also sets n.Key to be unique
node.Model.AddLink(parentdata, null, n, null);
}
var layout = new TreeLayout();
layout.Arrangement = TreeArrangement.FixedRoots;
layout.Angle = 90;
layout.TreeStyle = TreeStyle.Layered;
layout.LayerSpacing = 50;
layout.NodeSpacing = 20;
var subtree = node.FindTreeParts(EffectiveCollectionInclusions.SubTree);
layout.DoLayout(subtree.OfType(), subtree.OfType());
node.Diagram.CommitTransaction(“myDiagram_MouseDoubleClick”);
}
private void Expand_Click(object sender, RoutedEventArgs e)
{
}
private void CollapseExpandButton_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
Node n = Part.FindAncestor(button);
if (n != null)
{
n.Diagram.StartTransaction(“CollapseExpand”);
n.IsExpandedTree = !n.IsExpandedTree;
try
{
var layout = new TreeLayout();
layout.Angle = 90;
layout.TreeStyle = TreeStyle.Layered;
layout.Arrangement = TreeArrangement.FixedRoots;
layout.Alignment = TreeAlignment.CenterChildren;
layout.Id = “tree”;
layout.LayerSpacing = 50;
layout.NodeSpacing = 20;
if (n != null)
{
var subtree = n.FindTreeParts(EffectiveCollectionInclusions.SubTree);
var network = new TreeNetwork();
network.AddNodesAndLinks(subtree.OfType(), subtree.OfType());
layout.Network = network;
//layout.DoLayout(myDiagram.Nodes, myDiagram.Links);
layout.DoLayout(subtree.OfType(), subtree.OfType());
//myDiagram.Layout = layout;
//myDiagram.Layout.DoLayout(myDiagram.Nodes, myDiagram.Links);
//myDiagram.LayoutDiagram();
}
}
catch (System.Exception ex)
{
MessageBox.Show(string.Format(“Error Refreshing topology items : /n[{0}]”, ex.ToString()));
}
n.Diagram.CommitTransaction(“CollapseExpand”);
}
}
}
// Show text for any UIElement
public class ElementConverter : Converter
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return “(null)”;
UIElement elt = value as UIElement;
if (elt != null)
{
return elt.GetType().Name;
}
return value.ToString();
}
}
// Visible if there are any visual children for a UIElement
public class ChildrenVisibilityConverter : Converter
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
UIElement elt = value as UIElement;
if (elt != null)
{
return (VisualTreeHelper.GetChildrenCount(elt) > 0) ? Visibility.Visible : Visibility.Collapsed;
}
else
{
return Visibility.Visible;
}
}
}
}
*****************************************
XAML
<Window x:Class=“TestGoExam.Window1”
xmlns=“
http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=“
http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:go=“
http://schemas.nwoods.com/GoXam”
xmlns:local=“clr-namespace:TestGoExam”
Title=“Window1” Height=“300” Width=“300”>
<Window.Resources>
<go:BooleanStringConverter x:Key=“theButtonConverter” TrueString=“-” FalseString=“+” />
<Border Background=“{Binding Path=Data.Color}”
BorderBrush=“Black” BorderThickness=“1” Padding=“5” CornerRadius=“5”
go:Part.LayoutId=“{Binding Path=Data.LayoutId}”
go:Node.IsTreeExpanded=“False”
go:Node.SelectionAdorned=“True”
go:Node.Location=“{Binding Path=Data.Location, Mode=TwoWay}”
go:Node.LocationSpot=“Center”
go:Part.Selectable =“True”>
<Button x:Name=“myCollapseExpandButton” Cursor=“Hand”
Click=“CollapseExpandButton_Click”
Content=“{Binding Path=Node.IsExpandedTree, Converter={StaticResource theButtonConverter}}”
Visibility=“{Binding Path=Data.HasChildren, Converter={StaticResource booleanToVisibilityConverter}}”
HorizontalAlignment=“Center” VerticalAlignment=“Center” Width=“20” Height=“20” />
go:LinkPanel
<go:LinkShape Stroke=“Black” StrokeThickness=“1” />
<Polygon Fill=“Black” Points=“8 4 0 8 2 4 0 0” go:LinkPanel.Index=“-1”
go:LinkPanel.Alignment=“1 0.5” go:LinkPanel.Orientation=“Along” />
</go:LinkPanel>
</Window.Resources>
<Border Style=“{x:Null}”
Name=“OverviewBorderCtrl”
Background=“WhiteSmoke”
BorderThickness = “1”
HorizontalAlignment=“Right” VerticalAlignment=“Top”
BorderBrush=“Black”
Grid.RowSpan=“1”
Grid.Column=“1”
Panel.ZIndex=“10”
Visibility=“{Binding Path=local:m_OverviewVisible}”>
<go:Overview x:Name=“myOverview” Width=“200” Height=“100” >
go:Overview.BoxTemplate
<Rectangle Stroke=“
#B8CFE9” StrokeThickness=“12” Fill=“Transparent”
go:Part.LayerName=“Tool” Cursor=“SizeAll” RadiusX=“20” RadiusY=“20”/>
</go:Overview.BoxTemplate>
</go:Overview>
<go:Diagram x:Name=“myDiagram” Padding=“10”
LinkTemplate=“{StaticResource LinkTemplate}”
Stretch=“UniformToFill”
HorizontalContentAlignment=“Center”
VerticalContentAlignment=“Center”
NodeTemplate=“{StaticResource NodeTemplate}”
Grid.RowSpan=“2”
Grid.ColumnSpan =“2”
MouseDoubleClick=“myDiagram_MouseDoubleClick” HorizontalAlignment=“Center” VerticalAlignment=“Center”>
go:Diagram.Layout
go:MultiLayout
<go:TreeLayout Id=“Right” Angle=“0” Arrangement=“FixedRoots” SetsPortSpot=“False” />
<go:TreeLayout Id=“Down” Angle=“90” Arrangement=“FixedRoots” SetsPortSpot=“False” />
<go:TreeLayout Id=“Left” Angle=“180” Arrangement=“FixedRoots” SetsPortSpot=“False” />
<go:TreeLayout Id=“Up” Angle=“270” Arrangement=“FixedRoots” SetsPortSpot=“False” />
</go:MultiLayout>
</go:Diagram.Layout>
</go:Diagram>
*************************************************************************
example file:
<?xml version="1.0" encoding="UTF-8"?>