【问题标题】:UWP: Show ListView Items arranged in a circleUWP:显示圆形排列的 ListView 项目
【发布时间】:2017-02-23 08:00:09
【问题描述】:

我有一个 ListView,其中绑定了

我找到了这篇博文doing a similar thing in WPF,可以重写它以在 UWP 中使用吗?

【问题讨论】:

  • 到目前为止你尝试过什么,我很确定你可以为 UWP 编写该面板
  • 我确实将代码复制到了我的项目中,但很多命名空间似乎不同,我不确定我会在哪里寻找正确的,或者这是否是正确的方法。
  • 也许看看这篇文章codemag.com/article/1611061 它有一个形状像机场航站楼的列表......认为它可以适应圆形而不是矩形

标签: c# xaml listview uwp panel


【解决方案1】:

您提供的链接应该可以在 UWP 中使用,这是正确的做法。您只需要像这样更新命名空间:

using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace SomeNamespace
{
    public class CircularPanel : Panel
    {
        protected override Size MeasureOverride(Size availableSize)
        {
            foreach (UIElement child in Children)
                child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            return base.MeasureOverride(availableSize);
        }

        // Arrange stuff in a circle
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (Children.Count > 0)
            {
                // Center & radius of panel
                Point center = new Point(finalSize.Width / 2, finalSize.Height / 2);
                double radius = Math.Min(finalSize.Width, finalSize.Height) / 2.0;
                radius *= 0.8;   // To avoid hitting edges

                // # radians between children
                double angleIncrRadians = 2.0 * Math.PI / Children.Count;

                double angleInRadians = 0.0;

                foreach (UIElement child in Children)
                {
                    Point childPosition = new Point(
                        radius * Math.Cos(angleInRadians) + center.X,
                        radius * Math.Sin(angleInRadians) + center.Y);

                    child.Arrange(new Rect(childPosition, child.DesiredSize));

                    angleInRadians += angleIncrRadians;
                }
            }

            return finalSize;
        }
    }
}

【讨论】:

  • 看起来真的很棒,谢谢!中心对我来说有点偏离(项目大小的一半),所以我更新了中心点的计算:var ch = Children.FirstOrDefault().DesiredSize.Height; var cw = Children.FirstOrDefault().DesiredSize.Width; Point center = new Point((finalSize.Width - cw) / 2, (finalSize.Height - ch) / 2);
猜你喜欢
  • 2017-01-26
  • 1970-01-01
  • 2021-02-07
  • 2018-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-30
相关资源
最近更新 更多