Reputation: 318
Basically, I want to display a binary tree in WinRT. I have an ObservableCollection
which contains the values of the nodes.
What do you think is the best way to start trying with?
Upvotes: 0
Views: 159
Reputation: 608
You can use your own panel(custom), to achieve your requirement,
public class MyBinaryTreePanel : Panel
{
public double MaxRowHeight { get; set; }
public MyBinaryTreePanel()
{
MaxRowHeight = 0.0;
}
protected override Size ArrangeOverride(Size finalSize)
{
double rowHeight=0;
double columnWidth = finalSize.Width;
int total = Children.Count;
int temp = total;
int count = 0;
do
{
temp /= 2;
count++;
} while (temp != 1);
count++;
int Row = count;
MaxRowHeight = finalSize.Height / total;
double temrow = 0;
int i = 0;
for (int a = 0; a < Row; a++)
{
double temp34 = 0;
double tempColumn = 0;
columnWidth = ((finalSize.Width) / (Math.Pow(2, a)));
for (int b = 0; b < (Math.Pow(2, a)); b++)
{
if (i < total)
{
rowHeight = Children[i].DesiredSize.Height > MaxRowHeight ? Children[i].DesiredSize.Height : MaxRowHeight;
Children[i].Arrange(new Rect( tempColumn, temrow, columnWidth, rowHeight));
i++;
if (rowHeight >= temp34)
{
temp34 = rowHeight;
}
else
{
rowHeight = temp34;
}
tempColumn += columnWidth;
}
}
temrow += temp34;
}//
return finalSize;
}
protected override Size MeasureOverride(Size availableSize)
{
int total = Children.Count;
int temp = total;
int count = 0;
do
{
temp /= 2;
count++;
} while (temp != 1);
count++;
int Row = count;
MaxRowHeight = (availableSize.Height) / Row;
Size MyDesiredSize = new Size();
int i = 0;
for (int a = 0; a < Row; a++)
{
double value2 = 0.0;
for (int b = 0; b < (Math.Pow(2, a)); b++)
{
if (i < total)
{
Children[i].Measure(availableSize);
double value1 = Children[i].DesiredSize.Height;
if (value1 >= value2)
{
MyDesiredSize.Height = value1;
value2 = value1;
}
else
{
MyDesiredSize.Height = value2;
}
i++;
}
}
MyDesiredSize.Height = MyDesiredSize.Height > MaxRowHeight ? MyDesiredSize.Height : MaxRowHeight;
}
return MyDesiredSize;
}
}
I hope it will help you,
Regards, Joy Rex
Upvotes: 1
Reputation: 31724
If a "standard" TreeView
control doesn't satisfy your aesthetic needs - you could either try to build a tree out of some Shape
elements, possibly connected and most likely laid out on a Canvas
or alternatively to support huge trees - use DirectX - either with a native WinRT component or using SharpDX.
Upvotes: 2
Reputation: 31724
You can use the TreeView
control from WinRT Xaml Toolkit.
Here's sample usage: https://winrtxamltoolkit.codeplex.com/SourceControl/latest#WinRTXamlToolkit.Sample/Views/Controls/TreeViewTestPage.xaml
The control is ported from Silverlight Toolkit with the original as well as a touch friendlier template available. You can find WinRTXamlToolkit on NuGet.
Upvotes: 0