첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ RadialPanel.cs

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;

namespace TestProject
{
    /// <summary>
    /// 방사형 패널
    /// </summary>
    public class RadialPanel : Panel
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 최대 자식 높이
        /// </summary>
        private double maximumChildHeight;

        /// <summary>
        /// 둘레
        /// </summary>
        private double perimeter;
        
        /// <summary>
        /// 반경
        /// </summary>
        private double radius;

        /// <summary>
        /// 수정 팩터
        /// </summary>        
        private double adjustFactor;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 측정하기 (오버라이드) - MeasureOverride(availableSize)

        /// <summary>
        /// 측정하기 (오버라이드)
        /// </summary>
        /// <param name="availableSize">이용 가능한 크기</param>
        /// <returns>희망 크기</returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            this.perimeter = 0d;

            this.maximumChildHeight = 0d;
 
            foreach(UIElement childUIElement in Children)
            {
                childUIElement.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

                this.perimeter += childUIElement.DesiredSize.Width;

                this.maximumChildHeight = Math.Max(this.maximumChildHeight, childUIElement.DesiredSize.Height);
            }
 
            if(Children.Count > 2 && Children.Count != 4)
            {
                this.adjustFactor = 10d;
            }
 
            this.radius = this.perimeter / (2d * Math.PI) + this.adjustFactor;

            double squareSize = 2d * (this.radius + this.maximumChildHeight);

            return new Size(squareSize, squareSize);
        }

        #endregion
        #region 정렬하기 (오버라이드) - ArrangeOverride(finalSize)

        /// <summary>
        /// 정렬하기 (오버라이드)
        /// </summary>
        /// <param name="finalSize">최종 크기</param>
        /// <returns>최종 크기</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            double currentAngle   = 0d;
            double centerX        = 0d;
            double centerY        = 0d;
            double marginalAngle  = 0d;

            this.radius -= this.adjustFactor;
 
            centerX = finalSize.Width  / 2d;
            centerY = finalSize.Height / 2d;
  
            if(Children.Count != 0)
            {
                marginalAngle = 360d / Children.Count;
            }

            foreach(UIElement childUIElement in Children)
            {
                childUIElement.RenderTransform = new RotateTransform(currentAngle);

                childUIElement.Arrange(new Rect(new Point(centerX, centerX), new Size(childUIElement.DesiredSize.Width, childUIElement.DesiredSize.Height)));
 
                currentAngle += marginalAngle;
            }
 
            return finalSize;
        }

        #endregion
    }
}

 

728x90

 

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="방사형 패널 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="32">
    <Grid>
        <Border Margin="5" BorderThickness="1" BorderBrush="Purple" VerticalAlignment="Center" HorizontalAlignment="Center">
            <local:RadialPanel VerticalAlignment="Center" HorizontalAlignment="Center">
                <Button Padding="5" BorderBrush="Black" Background="RoyalBlue" Foreground="White" Content="버튼 1" />
                <Button Padding="5" BorderBrush="Black" Background="Red"       Foreground="White" Content="버튼 2" />
                <Button Padding="5" BorderBrush="Black" Background="Green"     Foreground="White" Content="버튼 3" />
                <Button Padding="5" BorderBrush="Black" Background="Purple"    Foreground="White" Content="버튼 4" />
                <Button Padding="5" BorderBrush="Black" Background="Yellow"    Foreground="Black" Content="버튼 5" />
            </local:RadialPanel>
        </Border>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요