[英]Drawing a binary tree in WinRT
Basically, I want to display a binary tree in WinRT. 基本上,我想在WinRT中显示一个二叉树。 I have an ObservableCollection
which contains the values of the nodes. 我有一个ObservableCollection
,其中包含节点的值。
What do you think is the best way to start trying with? 您认为开始尝试的最佳方法是什么?
如果“标准” TreeView
控件不能满足您的审美需求-您可以尝试使用某些Shape
元素(可能已连接并且很可能布置在Canvas
上)来构建树,或者尝试支持大树-使用DirectX-使用本地WinRT组件或使用SharpDX。
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 问候,雷克斯
You can use the TreeView
control from WinRT Xaml Toolkit. 您可以使用WinRT Xaml Toolkit中的TreeView
控件。
Here's sample usage: https://winrtxamltoolkit.codeplex.com/SourceControl/latest#WinRTXamlToolkit.Sample/Views/Controls/TreeViewTestPage.xaml 这是示例用法: 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. 该控件是从Silverlight Toolkit移植而来的,其中包含原始版本以及可用的触摸友好模板。 You can find WinRTXamlToolkit on NuGet . 您可以在NuGet上找到WinRTXamlToolkit 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.