728x90
반응형
728x170
■ Brush 클래스의 Opacity 속성을 사용해 브러시 투명도를 설정하는 방법을 보여준다.
▶ 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:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
Width="800"
Height="600"
Title="TestProject"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<DrawingBrush x:Key="CheckeredBackgroundDrawingBrushKey"
ViewportUnits="Absolute"
Viewport="0 0 10 10"
TileMode="Tile"
options:Freeze="True">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0 0 1 1" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing
Brush="#e2e2e2"
Geometry="M 0 0 L 0 0.5 0.5 0.5 0.5 1 1 1 1 0.5 0.5 0.5 0.5 0" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
<LinearGradientBrush x:Key="BlueHorizontalLinearGradientBrushKey"
StartPoint="0 0.5"
EndPoint="1 0.5"
options:Freeze="True">
<GradientStop Offset="0.0" Color="#993333cc" />
<GradientStop Offset="0.5" Color="#996666cc" />
</LinearGradientBrush>
<GradientStopCollection x:Key="GradientStopCollectionKey"
options:Freeze="True">
<GradientStop Offset="0.0" Color="Blue" />
<GradientStop Offset="0.5" Color="Black" />
<GradientStop Offset="1.0" Color="Transparent" />
</GradientStopCollection>
<DrawingGroup x:Key="DrawingGroupKey"
options:Freeze="True">
<DrawingGroup.Children>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<GeometryGroup>
<LineGeometry
StartPoint="0 0"
EndPoint="1 1" />
<LineGeometry
StartPoint="0 1"
EndPoint="1 0" />
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen
Thickness="0.2"
Brush="#3366ff" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing
Brush="Red"
Geometry="M 0.4 0.4 L 0.5 0.2 0.6 0.4 0.5 0.5" />
<GeometryDrawing
Brush="Blue"
Geometry="M 0.4 0.6 L 0.5 0.8 0.6 0.6 0.5 0.5" />
<GeometryDrawing
Brush="Black"
Geometry="M 0.4 0.4 L 0.2 0.5 0.4 0.6 0.5 0.5" />
<GeometryDrawing
Brush="Green"
Geometry="M 0.6 0.4 L 0.8 0.5 0.6 0.6 0.5 0.5" />
</DrawingGroup.Children>
</DrawingGroup>
</Window.Resources>
<Grid
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Grid.Row="2" Grid.Column="2" Grid.RowSpan="9" Grid.ColumnSpan="9"
Fill="{StaticResource CheckeredBackgroundDrawingBrushKey}" />
<TextBlock Grid.Row="0" Grid.Column="2">Opacity : 1.0</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="4">Opacity : 0.75</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="6">Opacity : 0.5</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="8">Opacity : 0.25</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="10">Opacity : 0.0</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">SolidColorBrush</TextBlock>
<Rectangle Grid.Row="2" Grid.Column="2"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush
Color="Blue"
Opacity="1" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="2" Grid.Column="4"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush
Color="Blue"
Opacity="0.75" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="2" Grid.Column="6"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush
Color="Blue"
Opacity="0.5" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="2" Grid.Column="8"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush
Color="Blue"
Opacity="0.25" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="2" Grid.Column="10"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush
Color="Blue"
Opacity="0" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Row="4" Grid.Column="0">LinearGradientBrush</TextBlock>
<Rectangle Grid.Row="4" Grid.Column="2"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush
Opacity="1"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="4" Grid.Column="4"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush
Opacity="0.75"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="4" Grid.Column="6"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush
Opacity="0.5"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="4" Grid.Column="8"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush
Opacity="0.25"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="4" Grid.Column="10"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush
Opacity="0"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Row="6" Grid.Column="0">RadialGradientBrush</TextBlock>
<Rectangle Grid.Row="6" Grid.Column="2"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<RadialGradientBrush
Opacity="1.0"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="6" Grid.Column="4"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<RadialGradientBrush
Opacity="0.75"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="6" Grid.Column="6"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<RadialGradientBrush
Opacity="0.5"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="6" Grid.Column="8"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<RadialGradientBrush
Opacity="0.25"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="6" Grid.Column="10"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<RadialGradientBrush
Opacity="0"
GradientStops="{StaticResource GradientStopCollectionKey}" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Row="8" Grid.Column="0">ImageBrush</TextBlock>
<Rectangle Grid.Row="8" Grid.Column="2"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<ImageBrush
Opacity="1.0"
ImageSource="IMAGE\pinkcherries.jpg" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="8" Grid.Column="4"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<ImageBrush
Opacity="0.75"
ImageSource="IMAGE\pinkcherries.jpg" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="8" Grid.Column="6"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<ImageBrush
Opacity="0.5"
ImageSource="IMAGE\pinkcherries.jpg" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="8" Grid.Column="8"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<ImageBrush
Opacity="0.25"
ImageSource="IMAGE\pinkcherries.jpg" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="8" Grid.Column="10"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<ImageBrush
Opacity="0"
ImageSource="IMAGE\pinkcherries.jpg" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Row="10" Grid.Column="0">DrawingBrush</TextBlock>
<Rectangle Grid.Row="10" Grid.Column="2"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Opacity="1.0"
Drawing="{StaticResource DrawingGroupKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="10" Grid.Column="4"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Opacity="0.75"
Drawing="{StaticResource DrawingGroupKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="10" Grid.Column="6"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Opacity="0.5"
Drawing="{StaticResource DrawingGroupKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="10" Grid.Column="8"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Opacity="0.25"
Drawing="{StaticResource DrawingGroupKey}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="10" Grid.Column="10"
Width="100"
Height="50"
StrokeThickness="1"
Stroke="Black">
<Rectangle.Fill>
<DrawingBrush
Opacity="0"
Drawing="{StaticResource DrawingGroupKey}" />
</Rectangle.Fill>
</Rectangle>
</Grid>
</Window>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Brush 클래스 : 브러시 사용하기 (0) | 2023.03.16 |
---|---|
[C#/WPF] RadialGradientBrush 엘리먼트 : 애니메이션 설정하기 (0) | 2023.03.16 |
[C#/WPF] GradientBrush 클래스 : SpreadMethod 속성 사용하기 (0) | 2023.03.16 |
[C#/WPF] Shape 클래스 : StrokeDashArray/StrokeDashOffset 속성 사용하기 (0) | 2023.03.16 |
[C#/WPF] GradientBrush 클래스 : GradientStops 속성 사용하기 (0) | 2023.03.14 |
[C#/WPF] DrawingBrush 엘리먼트 사용하기 (0) | 2023.03.09 |
[C#/WPF] DrawingBrush 클래스 사용하기 (0) | 2023.03.09 |
[C#/WPF] RadialGradientBrush 엘리먼트 사용하기 (0) | 2023.03.09 |
[C#/WPF] RadialGradientBrush 클래스 사용하기 (0) | 2023.03.09 |
[C#/WPF] 바인딩 방향 설정하기 (0) | 2023.03.07 |
댓글을 달아 주세요