728x90
반응형
728x170
■ StreamGeometry 클래스를 사용하는 방법을 보여준다.
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 모니터 추가/제거시 이벤트 처리하기 (0) | 2021.02.08 |
---|---|
[C#/WPF] Shape 클래스 : 커스텀 호(Arc) 만들기 (0) | 2021.02.07 |
[C#/WPF] DrawingContext 클래스 : DrawGlyphRun 메소드를 사용해 텍스트 그리기 (0) | 2021.02.07 |
[C#/WPF] Shape 클래스 : DefiningGeometry 속성을 사용해 커스텀 도형 만들기 (0) | 2021.02.07 |
[C#/WPF] TextBlock 엘리먼트 : Text 속성에서 개행 문자 사용하기 (0) | 2021.02.07 |
[C#/WPF] FrameworkElement 클래스 : 커스텀 엘리먼트 만들기 (0) | 2021.02.07 |
[C#/WPF] DrawingVisual 클래스 : 커스텀 비주얼 만들기 (0) | 2021.02.07 |
[C#/WPF] LinearGradientBrush 엘리먼트 : MappingMode 속성을 사용해 절대 좌표 설정하기 (0) | 2021.02.07 |
[C#/WPF] x:Static 태그 확장 : SystemColors 클래스의 HighlightBrush 정적 속성 값 사용하기 (0) | 2021.02.07 |
[C#/WPF] Style 엘리먼트 : BasedOn 속성을 사용해 기존 디폴트 스타일에 스타일 트리거 추가하기 (0) | 2021.02.07 |
댓글을 달아 주세요