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

■ Brush 클래스의 Opacity 속성을 사용해 브러시 투명도를 설정하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요