基本上,我想在WinRT中显示二叉树。我有一个ObservableCollection
,其中包含节点的值。
您认为开始尝试的最佳方式是什么?
答案 0 :(得分:2)
如果是"标准" TreeView
控制不能满足您的审美需求 - 您可以尝试使用Shape
个元素构建一个树,这些元素可能已连接,很可能是Canvas
或者{{1}}。支持巨大的树 - 使用DirectX - 使用本机WinRT组件或使用SharpDX。
答案 1 :(得分:1)
您可以使用自己的面板(自定义)来满足您的要求,
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;
}
}
我希望它会对你有帮助,
此致 Joy Rex
答案 2 :(得分:0)
您可以使用WinRT Xaml Toolkit中的TreeView
控件。
该控件从Silverlight Toolkit移植,具有可用的原始模板和触摸友好模板。您可以找到WinRTXamlToolkit on NuGet。