我有一個ListView與< 12項綁定到它。我想將這些項目安排在一個圓圈中,同時仍然可以使用ListView功能(selectedItem等)。儘管如此,滾動並不是必需的。UWP:顯示列表視圖項目排列在一個圓圈
我發現了這個博客文章doing a similar thing in WPF,這可以重寫爲用於UWP嗎?
我有一個ListView與< 12項綁定到它。我想將這些項目安排在一個圓圈中,同時仍然可以使用ListView功能(selectedItem等)。儘管如此,滾動並不是必需的。UWP:顯示列表視圖項目排列在一個圓圈
我發現了這個博客文章doing a similar thing in WPF,這可以重寫爲用於UWP嗎?
您提供的鏈接應該在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; ((finalSize.Width - cw)/ 2,(finalSize.Height - ch)/ 2);' – Thomas
你嘗試過什麼到目前爲止,我敢肯定,你可以寫一個面板UWP – Alex
我做的代碼複製到我的項目,但很多的命名空間似乎是不同的,我不知道我會在哪裏尋找正確的,或者如果這是正確的方法。 – Thomas
也許看看這篇文章http://www.codemag.com/article/1611061它具有一個形狀爲機場終端的列表......認爲它可以適應一個圓圈而不是矩形 – Depechie