Universal Windows Platform – Radial Control

Radial Control demonstrates how to create a Radial Panel Control

Step 1

If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu find and select Visual Studio 2017.


Step 2

Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…


Step 3

From New Project choose Visual C# from Installed, Templates then choose Blank App (Universal Windows) and then type in the Name as RadialControl and select a Location and then select Ok to create the Project

Step 4

Then in New Universal Windows Project you need to select the Target Version this should be at least the Windows 10 Fall Creators Update (10.0; Build 16299) and the Minimum Version to be the same.


The Target Version will control what features your application can use in Windows 10 so by picking the most recent version you’ll be able to take advantage of those features. To make sure you always have the most recent version, in Visual Studio 2017 select Tools Extensions and Updates… then and then see if there are any Updates

Step 5

Once done select from the Menu, Project, then Add New Item…


Step 6

From the Add New Item window select Visual C#, then Code from Installed then select Code File from the list, then type in the Name as RadialPanel.cs before selecting Add to add the file to the Project


Step 7

Once in the Code View for RadialPanel.cs the following should be entered:

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

namespace RadialControl
    public partial class RadialPanel : Panel
        private bool _ignorePropertyChange;

        private static void OnIsOrientedPropertyChanged(DependencyObject d,
            DependencyPropertyChangedEventArgs e)
            RadialPanel source = (RadialPanel)d;
            bool value = (bool)e.NewValue;
            if (source._ignorePropertyChange)
                source._ignorePropertyChange = false;

        private static void OnItemHeightOrWidthPropertyChanged(DependencyObject d,
            DependencyPropertyChangedEventArgs e)
            RadialPanel source = (RadialPanel)d;
            double value = (double)e.NewValue;
            if (source._ignorePropertyChange)
                source._ignorePropertyChange = false;
            if (!double.IsNaN(value) && ((value <= 0.0) || double.IsPositiveInfinity(value)))
                source._ignorePropertyChange = true;
                source.SetValue(e.Property, (double)e.OldValue);
                throw new ArgumentException("OnItemHeightOrWidthPropertyChanged InvalidValue", "value");

        public static readonly DependencyProperty ItemHeightProperty =
        DependencyProperty.Register("ItemHeight", typeof(double), typeof(RadialPanel),
        new PropertyMetadata(double.NaN, OnItemHeightOrWidthPropertyChanged));

        public static readonly DependencyProperty ItemWidthProperty =
        DependencyProperty.Register("ItemWidth", typeof(double), typeof(RadialPanel),
        new PropertyMetadata(double.NaN, OnItemHeightOrWidthPropertyChanged));

        public static readonly DependencyProperty IsOrientedProperty =
        DependencyProperty.Register("IsOriented", typeof(bool), typeof(RadialPanel),
        new PropertyMetadata(false, OnIsOrientedPropertyChanged));

        public double ItemHeight
            get { return (double)GetValue(ItemHeightProperty); }
            set { SetValue(ItemHeightProperty, value); }

        public double ItemWidth
            get { return (double)GetValue(ItemWidthProperty); }
            set { SetValue(ItemWidthProperty, value); }

        public bool IsOriented
            get { return (bool)GetValue(IsOrientedProperty); }
            set { SetValue(IsOrientedProperty, value); }

        protected override Size MeasureOverride(Size constraint)
            double itemWidth = ItemWidth;
            double itemHeight = ItemHeight;
            bool hasFixedWidth = !double.IsNaN(itemWidth);
            bool hasFixedHeight = !double.IsNaN(itemHeight);
            Size itemSize = new Size(
                hasFixedWidth ? itemWidth : constraint.Width,
                hasFixedHeight ? itemHeight : constraint.Height);
            foreach (UIElement element in Children)
            return itemSize;

        protected override Size ArrangeOverride(Size finalSize)
            double itemWidth = ItemWidth;
            double itemHeight = ItemHeight;
            bool hasFixedWidth = !double.IsNaN(itemWidth);
            bool hasFixedHeight = !double.IsNaN(itemHeight);
            double radiusX = finalSize.Width * 0.5;
            double radiusY = finalSize.Height * 0.5;
            double count = Children.Count;
            double deltaAngle = 2 * Math.PI / count;
            Point centre = new Point(finalSize.Width / 2,
                finalSize.Height / 2);
            for (int i = 0; i < count; i++)
                UIElement element = Children[i];
                Size elementSize = new Size(
                hasFixedWidth ? itemWidth : element.DesiredSize.Width,
                hasFixedHeight ? itemHeight : element.DesiredSize.Height);
                double angle = i * deltaAngle;
                double x = centre.X + radiusX * Math.Cos(angle)
                    - elementSize.Width / 2;
                double y = centre.Y + radiusY * Math.Sin(angle)
                    - elementSize.Height / 2;
                if (IsOriented)
                    element.RenderTransform = null;
                    element.RenderTransformOrigin = new Point(0.5, 0.5);
                    element.RenderTransform = new RotateTransform()
                        Angle = angle * 180 / Math.PI
                element.Arrange(new Rect(x, y,
                    elementSize.Width, elementSize.Height));
            return finalSize;

In the Radial.cs there are using statements to include the necessary functionality. There is an OnIsOrientedPropertyChanged and OnItemHeightOrWidthPropertyChanged to respond to Events that will happen within the Control. There are DependencyProperty items and Properties for ItemHeight, ItemWidth and IsOriented. There is MeasureOverride and ArrangeOverride that will help to place Controls that will be Children of the Panel a and to position them at different degrees of rotation around a centre point.

Step 8

Once done select from the Menu, Build, then Build Solution


Step 9

In the Solution Explorer select MainPage.xaml


Step 10

From the Menu choose View and then Designer


Step 11

The Design View will be displayed along with the XAML View and in this between the Grid and /Grid elements, enter the following XAML:

<local:RadialPanel Height="300" Width="300">
	<Rectangle Width="50" Height="50" Fill="Black"/>
	<Rectangle Width="50" Height="50" Fill="Gray"/>
	<Rectangle Width="50" Height="50" Fill="Red"/>
	<Rectangle Width="50" Height="50" Fill="Orange"/>
	<Rectangle Width="50" Height="50" Fill="Yellow"/>
	<Rectangle Width="50" Height="50" Fill="Green"/>
	<Rectangle Width="50" Height="50" Fill="Cyan"/>
	<Rectangle Width="50" Height="50" Fill="Blue"/>
	<Rectangle Width="50" Height="50" Fill="Magenta"/>
	<Rectangle Width="50" Height="50" Fill="Purple"/>

The block of XAML represents the RadialPanel Control with its Children set to some Rectangle Controls.

Step 12

That completes the Universal Windows Platform Application so Save the Project then in Visual Studio select the Local Machine to run the Application


Step 13

After the Application started running it should then appear displaying the RadialPanel Control in the Application


Step 14

To Exit the Application select the Close button in the top right of the Application


Creative Commons License

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s