0

基本上,我想在 WinRT 中显示二叉树。我有一个ObservableCollection包含节点的值。

您认为开始尝试的最佳方式是什么?

4

3 回答 3

2

如果“标准”TreeView控件不能满足您的审美需求 - 您可以尝试用一些Shape元素构建一棵树,这些元素可能已连接并且很可能布局在 a 上,Canvas或者支持巨大的树 - 使用 DirectX - 或者使用原生WinRT 组件或使用 SharpDX。

于 2014-03-21T00:18:48.480 回答
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;
        }
    }

希望对你有帮助

问候, 乔伊雷克斯

于 2014-03-23T17:56:54.613 回答
0

您可以使用TreeViewWinRT Xaml Toolkit 中的控件。

这是示例用法:https ://winrtxamltoolkit.codeplex.com/SourceControl/latest#WinRTXamlToolkit.Sample/Views/Controls/TreeViewTestPage.xaml

该控件是从 Silverlight Toolkit 移植的,带有原始模板以及对触摸更友好的模板。您可以在 NuGet 上找到WinRTXamlToolkit

于 2014-03-21T00:15:00.340 回答