博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
转一个orbitpanel
阅读量:6173 次
发布时间:2019-06-21

本文共 6482 字,大约阅读时间需要 21 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Windows.Foundation;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;namespace App8{    public class orbitpanel:Panel    {        int i = 0;        public int orbitsnunber        {            get { return (int)GetValue(OrbitsProperty); }            set { SetValue(OrbitsProperty,value); }        }        public static readonly DependencyProperty OrbitsProperty = DependencyProperty.Register("orbitsnunber", typeof(int), typeof(orbitpanel), new PropertyMetadata(1, OnOrbitsChanged));        private static void OnOrbitsChanged(DependencyObject d,DependencyPropertyChangedEventArgs e){if ((int)e.NewValue < 1){throw new ArgumentException("Orbits must be greater than or equal to 1.");}}        public static int GetOrbit(DependencyObject obj)        {            return (int)obj.GetValue(OrbitProperty);        }        public static void SetOrbit(DependencyObject obj, int value)        {            obj.SetValue(OrbitProperty, value);        }        public static readonly DependencyProperty OrbitProperty =DependencyProperty.RegisterAttached("Orbit",typeof(int),typeof(orbitpanel),new PropertyMetadata(0));        protected override Size MeasureOverride(Size availableSize)        {            var sortedItems = SortElements();            double max = 0.0;            foreach (List
orbitItems in sortedItems) { if (orbitItems.Count > 0) { foreach (UIElement element in orbitItems) { element.Measure(availableSize); if (element.DesiredSize.Width > max) max = element.DesiredSize.Width; if (element.DesiredSize.Height > max) max = element.DesiredSize.Height; } } } Size desiredSize = new Size(max * orbitsnunber * 2, max * orbitsnunber * 2); if (double.IsInfinity(availableSize.Height) || double.IsInfinity(availableSize.Width)) return desiredSize; else return availableSize; } protected override Size ArrangeOverride(Size finalSize) { var sortedItems = SortElements(); double orbitSpacing = CalculateOrbitSpacing(finalSize); foreach (List
orbitItems in sortedItems) { int count = orbitItems.Count; if (count > 0) { double circumference = 2 * Math.PI * orbitSpacing * (i + 1); double slotSize = Math.Min(orbitSpacing, circumference / count); double maxSize = Math.Min(orbitSpacing, slotSize); double angleIncrement = 360 / count; double currentAngle = 0; Point centerPoint = new Point(finalSize.Width / 2, finalSize.Height / 2); foreach (UIElement element in orbitItems) { double angle = Math.PI / 180 * (currentAngle - 90); double left = orbitSpacing * (i + 1) * Math.Cos(angle); double top = orbitSpacing * (i + 1) * Math.Sin(angle); Rect finalRect = new Rect( centerPoint.X + left - element.DesiredSize.Width / 2, centerPoint.Y + top - element.DesiredSize.Height / 2, element.DesiredSize.Width, element.DesiredSize.Height); element.Arrange(finalRect); currentAngle += angleIncrement; } } } return base.ArrangeOverride(finalSize); } private List
[] SortElements() { var list = new List
[orbitsnunber]; for (int i = 0; i < orbitsnunber; i++) { if (i == orbitsnunber - 1) list[i] = (from UIElement child in Children where GetOrbit(child) >= i select child).ToList
(); else list[i] = (from UIElement child in Children where GetOrbit(child) == i select child).ToList
(); } return list; } private double CalculateOrbitSpacing(Size availableSize) { double constrainingSize = Math.Min( availableSize.Width, availableSize.Height); double space = constrainingSize / 2; return space / orbitsnunber; } }} 使用方法

 <local:orbitpanel orbitsnunber="1">

            <Image x:Name="image"  local:orbitpanel.Orbit="0"   HorizontalAlignment="Left" Height="166" PointerEntered="image_PointerEntered_1" PointerExited="image_PointerExited_1"  Margin="449,349,0,0" VerticalAlignment="Top" Width="261" Source="" RenderTransformOrigin="0.5,0.5">               
            </Image>      
        <Image   local:orbitpanel.Orbit="0"   HorizontalAlignment="Left" Height="166" PointerEntered="image_PointerEntered_1" PointerExited="image_PointerExited_1"  Margin="449,349,0,0" VerticalAlignment="Top" Width="261" Source="" RenderTransformOrigin="0.5,0.5">          
        </Image>
        <Image   local:orbitpanel.Orbit="0"   HorizontalAlignment="Left" Height="166" PointerEntered="image_PointerEntered_1" PointerExited="image_PointerExited_1"  Margin="449,349,0,0" VerticalAlignment="Top" Width="261" Source="" RenderTransformOrigin="0.5,0.5">          </Image>       
        <Image  local:orbitpanel.Orbit="0"   HorizontalAlignment="Left" Height="166" PointerEntered="image_PointerEntered_1" PointerExited="image_PointerExited_1"  Margin="449,349,0,0" VerticalAlignment="Top" Width="261" Source="" RenderTransformOrigin="0.5,0.5">           
        </Image>
        <Image  local:orbitpanel.Orbit="0"   HorizontalAlignment="Left" Height="166" PointerEntered="image_PointerEntered_1" PointerExited="image_PointerExited_1"  Margin="449,349,0,0" VerticalAlignment="Top" Width="261" Source="" RenderTransformOrigin="0.5,0.5">           
        </Image>
        <Image  local:orbitpanel.Orbit="0"   HorizontalAlignment="Left" Height="166" PointerEntered="image_PointerEntered_1" PointerExited="image_PointerExited_1"  Margin="449,349,0,0" VerticalAlignment="Top" Width="261" Source="" RenderTransformOrigin="0.5,0.5">           
        </Image>

    </local:orbitpanel>

 

 

转载于:https://www.cnblogs.com/gisbeginner/archive/2012/09/12/2681886.html

你可能感兴趣的文章
(一一〇)二维数组里找零最多的题目
查看>>
dotCloud say PostgreSQL does not scale for High Availability on the dotCloud Platform
查看>>
Tomcat shutdown无法结束进程的问题
查看>>
Android源码阅读小技巧
查看>>
基于github androidmvp代码 对mvp进行思考
查看>>
javascript设计模式小结
查看>>
ECMAScript6简介
查看>>
谈一下PHP站点页面静态化的原理
查看>>
分享专业网站建设多年来对网页制作的经验
查看>>
windows查看占用端口程序
查看>>
Linux系统下测试磁盘读写IO性能(物理机和虚拟机的测试)
查看>>
java中带回调函数的字符串替换,类似js中的replace(rgExp,function)
查看>>
注解使用
查看>>
第五章 面向对象(二)
查看>>
交换机接入安全
查看>>
Java Axis Service 手动调用WebService 入参为NULL
查看>>
linux学习笔记九:一般Tarball软件安装流程(以ntp-4.2.4p7.tar.gz为例)
查看>>
数据刷新-界面加载不空白的钥匙
查看>>
一句话搞定webmap(一)——轻地图组件
查看>>
c++数据类型间的转换
查看>>