728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] MarkupExtension 클래스 : 마크업 확장 사용하기 (0) | 2018.02.18 |
---|---|
[C#/WPF] MediaElement 클래스 : 동영상 재생하기 (0) | 2017.06.14 |
[C#/WPF] ListView 클래스 : 그리드 뷰 컬럼 헤더 클릭시 정렬하기 (0) | 2017.06.11 |
[C#/WPF] DataGrid 클래스 : RowValidationRules 속성을 사용해 검증하기 (0) | 2017.06.11 |
[C#/WPF] DataGrid 클래스 : 그룹핑, 정렬 및 필터링 사용하기 (0) | 2017.06.11 |
[C#/WPF] MessageBox 클래스 : 메시지 박스 사용하기 (0) | 2017.06.11 |
[C#/WPF] DataGrid 클래스 : ADO.NET 엔터티 데이터 모델 바인딩 하기 (0) | 2017.06.11 |
[C#/WPF] 애니메이션 버튼 사용하기 (0) | 2017.06.11 |
[C#/WPF] DesignInstance 확장 태그 사용하기 (0) | 2017.06.11 |
[C#/WPF] ObservableCollection<T> 클래스 : 바인딩 설정하기 (0) | 2017.06.11 |
댓글을 달아 주세요