Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Bug in XamOrgChart
posted

I discovered anevil(because very hard to find) bug, which cost me at least an hour of my time (just because I was lucky, and tried unlikely stuff out).

XamOrgChart tries to outsmart the coder, and evaluates all public properties, and if the type of the property is IEnumerable, it's obviously treated as ItemsSource (for the Children) (or whatever XamOrgChart does).

I created a small example demonstrating the problem:

 

XAML:

<

UserControl xmlns:ig="http://schemas.infragistics.com/xaml" x:Class

="XamOrgChartBug.MainPage"

xmlns

="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x

="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d

="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc

="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable

="d"

d:DesignHeight="300" d:DesignWidth

="400">

<Grid x:Name="LayoutRoot" Background

="White">

<ig:XamOrgChart

InitialTreeDepth

="2"

LevelsToExpand

="1"

ItemsSource="{Binding

.}"

>

<ig:XamOrgChart.GlobalNodeLayouts

>

<ig:OrgChartNodeLayout

TargetTypeName

="Tree_Type"

Key="Children"

DisplayMemberPath

="Text"

>

</ig:OrgChartNodeLayout

>

</ig:XamOrgChart.GlobalNodeLayouts

>

</ig:XamOrgChart

>

</Grid

>

</

UserControl

>

 

Xaml.cs:

public partial class MainPage :

UserControl

{

public

MainPage()

{

InitializeComponent();

var root = new Tree_Type

()

{

Parent =

null

,

Text =

"root"

,

};

root.Children =

Enumerable.Range(0, 3).Select(x => new Tree_Type

()

{

Parent = root,

Text =

"c"

+ x,

});

this.DataContext = new Tree_Type

[] { root };

}

}

public class

Tree_Type

{

public string Text { get; set

;}

public IEnumerable<Tree_Type> Children { get; set

; }

public Tree_Type Parent { get; set

; }

 

public IEnumerable<Tree_Type

> Parents

{

get

{

var p = this

.Parent;

while (p != null

)

{

yield return

p;

p =

this

.Parent;

}

}

}

}


 

When the project is started, it crashes with a meaningless error - if ran on IIS, you get "StackOverflow" exception. (probably IIS responsible...not sure - at least in my real project I got stackoverflow).

If the property "Parents" is commented in class "Tree_Type" there is no crash, and XamOrgChart is displayed.

What the heck is XamOrgChart doing with my public properties?! It should only touch those properties which I defined in the Xaml!!!

Regards

Johannes