■ Path 클래스 : Path 마크업 구문 사용하기 (코드)

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainPage.xaml

 

 

<Page x:Class="TestProject.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Grid Name="rootGrid"

        Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

    </Grid>

</Page>

 

 

MainPage.xaml.cs

 

 

using Windows.UI;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Markup;

using Windows.UI.Xaml.Media;

using Windows.UI.Xaml.Shapes;

 

namespace TestProject

{

    /// <summary>

    /// 메인 페이지

    /// </summary>

    public sealed partial class MainPage : Page

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainPage()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainPage()

        {

            InitializeComponent();

 

            Path path = new Path();

 

            path.Stroke              = new SolidColorBrush(Colors.Red);

            path.StrokeThickness     = 12;

            path.StrokeLineJoin      = PenLineJoin.Round;

            path.HorizontalAlignment = HorizontalAlignment.Center;

            path.VerticalAlignment   = VerticalAlignment.Center;

            path.Data                = GetGeometry

            (

                "M 0 0 L 0 100 M 0 50 L 50 50 M 50 0 L 50 100 " +

                "M 125 0 C 60 -10, 60 60, 125 50, 60 40, 60 110, 125 100 " +

                "M 150 0 L 150 100, 200 100 " +

                "M 225 0 L 225 100, 275 100 " +

                "M 300 50 A 25 50 0 1 0 300 49.9"

            );

 

            this.rootGrid.Children.Add(path);

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 기하 구하기 - GetGeometry(source)

 

        /// <summary>

        /// 기하 구하기

        /// </summary>

        /// <param name="source">소스 문자열</param>

        /// <returns>기하</returns>

        private Geometry GetGeometry(string source)

        {

            string xaml =  "<Path xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +

                           "<Path.Data>" + source + "</Path.Data>"+

                           "</Path>";

 

            Path path = XamlReader.Load(xaml) as Path;

 

            Geometry geometry = path.Data;

 

            path.Data = null;

 

            return geometry;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker