728x90
반응형
728x170
■ DrawingBrush 엘리먼트를 사용하는 방법을 보여준다.
▶ MainWindow.xaml
<Window Name="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="TestProject"
FontFamily="나눔고딕코딩"
FontSize="16">
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<StackPanel Margin="10">
<TextBlock>
A DrawingBrush paints an area with a drawing.<LineBreak />
It may also be used to create a pattern. The following are some examples.
</TextBlock>
<StackPanel
Margin="10"
Orientation="Horizontal">
<Rectangle
Margin="10"
Width="100"
Height="100"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing
Brush="Gray"
Geometry="M 0 0.1 L 0.1 0 1 0.9 0.9 1 z" />
<GeometryDrawing
Brush="Gray"
Geometry="M 0.9 0 L 1 0.1 0.1 1 0 0.9 z" />
<GeometryDrawing
Brush="#ffff00"
Geometry="M 0.25 0.25 L 0.5 0.125 0.75 0.25 0.5 0.5 z" />
<GeometryDrawing
Brush="Black"
Geometry="M 0.25 0.75 L 0.5 0.875 0.75 0.75 0.5 0.5 z" />
<GeometryDrawing
Brush="#ff0000"
Geometry="M 0.25 0.75 L 0.125 0.5 0.25 0.25 0.5 0.5 z" />
<GeometryDrawing
Brush="MediumBlue"
Geometry="M 0.75 0.25 L 0.875 0.5 0.75 0.75 0.5 0.5 z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle
Margin="10"
Width="100"
Height="100"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Viewport="0 0 0.5 0.5"
TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing
Brush="Gray"
Geometry="M 0 0.1 L 0.1 0 1 0.9 0.9 1 z" />
<GeometryDrawing
Brush="Gray"
Geometry="M 0.9 0 L 1 0.1 0.1 1 0 0.9 z" />
<GeometryDrawing
Brush="#ffff00"
Geometry="M 0.25 0.25 L 0.5 0.125 0.75 0.25 0.5 0.5 z" />
<GeometryDrawing
Brush="Black"
Geometry="M 0.25 0.75 L 0.5 0.875 0.75 0.75 0.5 0.5 z" />
<GeometryDrawing
Brush="#ff0000"
Geometry="M 0.25 0.75 L 0.125 0.5 0.25 0.25 0.5 0.5 z" />
<GeometryDrawing
Brush="MediumBlue"
Geometry="M 0.75 0.25 L 0.875 0.5 0.75 0.75 0.5 0.5 z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle
Margin="10"
Width="100"
Height="100"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Viewport="0 0 0.1 0.1"
TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing
Brush="Gray"
Geometry="M 0 0.1 L 0.1 0 1 0.9 0.9 1 z" />
<GeometryDrawing
Brush="Gray"
Geometry="M 0.9 0 L 1 0.1 0.1 1 0 0.9 z" />
<GeometryDrawing
Brush="#ffff00"
Geometry="M 0.25 0.25 L 0.5 0.125 0.75 0.25 0.5 0.5 z" />
<GeometryDrawing
Brush="Black"
Geometry="M 0.25 0.75 L 0.5 0.875 0.75 0.75 0.5 0.5 z" />
<GeometryDrawing
Brush="#ff0000"
Geometry="M 0.25 0.75 L 0.125 0.5 0.25 0.25 0.5 0.5 z" />
<GeometryDrawing
Brush="MediumBlue"
Geometry="M 0.75 0.25 L 0.875 0.5 0.75 0.75 0.5 0.5 z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
<TextBlock
Margin="0 10 0 0">
The following rectangles are filled with a drawing brush.<LineBreak />
Notice how the patterns defined by the DrawingBrush expand to fill the area of the rectangle.
</TextBlock>
<StackPanel
Margin="10"
Orientation="Horizontal">
<Rectangle
Margin="10"
Width="100"
Height="100"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="MediumBlue">
<GeometryDrawing.Geometry>
<GeometryGroup>
<EllipseGeometry Center="0.5 0.5" RadiusX="0.2" RadiusY="0.45" />
<EllipseGeometry Center="0.5 0.5" RadiusX="0.45" RadiusY="0.2" />
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen
Thickness="0.1"
Brush="Black" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle
Margin="10"
Width="200"
Height="100"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="MediumBlue">
<GeometryDrawing.Geometry>
<GeometryGroup>
<EllipseGeometry Center="0.5 0.5" RadiusX="0.2" RadiusY="0.45" />
<EllipseGeometry Center="0.5 0.5" RadiusX="0.45" RadiusY="0.2" />
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen
Thickness="0.1"
Brush="Black" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle
Margin="10"
Width="100"
Height="200"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="MediumBlue">
<GeometryDrawing.Geometry>
<GeometryGroup>
<EllipseGeometry Center="0.5 0.5" RadiusX="0.2" RadiusY="0.45" />
<EllipseGeometry Center="0.5 0.5" RadiusX="0.45" RadiusY="0.2" />
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen
Thickness="0.1"
Brush="Black" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
</StackPanel>
</StackPanel>
</Window>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] SolidColorBrush 클래스 : Color/Opacity 속성 애니메이션 설정하기 (0) | 2023.03.18 |
---|---|
[C#/WPF] RadioButton 엘리먼트 : 글래스 효과 라디오 버튼 만들기 (0) | 2023.03.18 |
[C#/WPF] DrawingBrush 엘리먼트 : 드로잉 브러시 애니메이션 만들기 (0) | 2023.03.18 |
[C#/WPF] ImageDrawing 엘리먼트 사용하기 (0) | 2023.03.18 |
[C#/WPF] DrawingBrush 엘리먼트 : Transform/RelativeTransform 속성 사용하기 (0) | 2023.03.18 |
[C#/WPF] VisualBrush 엘리먼트 : 반사 효과 만들기 (0) | 2023.03.17 |
[C#/WPF] DrawingBrush 엘리먼트 사용하기 (0) | 2023.03.17 |
[C#/WPF] DrawingBrush 엘리먼트 : 배경 애니메이션 만들기 (0) | 2023.03.17 |
[C#/WPF] Image 엘리먼트 : OpacityMask 속성에서 LinearGradientBrush 객체 사용하기 (0) | 2023.03.16 |
[C#/WPF] Image 엘리먼트 : OpacityMask 속성에서 ImageBrush 객체 사용하기 (0) | 2023.03.16 |
댓글을 달아 주세요