첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

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
    }
}

 

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="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
TAG , , ,

댓글을 달아 주세요