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

■ StreamGeometry 클래스를 사용하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ CustomVisual.cs

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

namespace TestProject
{
    /// <summary>
    /// 커스텀 비주얼
    /// </summary>
    public class CustomVisual : DrawingVisual
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - CustomVisual()

        /// <summary>
        /// 생성자
        /// </summary>
        public CustomVisual()
        {
            StreamGeometry streamGeometry = new StreamGeometry();

            using(StreamGeometryContext streamGeometryContext = streamGeometry.Open())
            {
                streamGeometryContext.BeginFigure(new Point(150.0, 150.0), true, true);

                streamGeometryContext.LineTo(new Point(210.0, 105.0), true, true);
                streamGeometryContext.LineTo(new Point(270.0, 150.0), true, true);
                streamGeometryContext.LineTo(new Point(270.0, 45.0 ), true, true);
                streamGeometryContext.LineTo(new Point(210.0, 90.0 ), true, true);
                streamGeometryContext.LineTo(new Point(150.0, 45.0 ), true, true);
            }

            using(DrawingContext drawingContext = RenderOpen())
            {
                drawingContext.DrawGeometry
                (
                    Brushes.DarkRed,
                    new Pen(Brushes.Blue, 2),
                    streamGeometry
                );
            }
        }

        #endregion
    }
}

 

▶ 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="StreamGeometry 클래스 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Margin="10">
        <Grid.Background>
            <VisualBrush
                Viewport="0 0 0.25 0.25"
                TileMode="Tile">
                <VisualBrush.Visual>
                    <local:CustomVisual />
                </VisualBrush.Visual>
            </VisualBrush>
        </Grid.Background>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요