Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

DrawingBrushを使って塗りつぶし領域に合うようにスケーリングさせる

アプリ実行


ソースコード

App.xaml
<Application x:Class="HelloWorld.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
</Application>
MainWindow.xaml
<Window x:Class="HelloWorld.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Rectangle>
        <Rectangle.Fill>
            <DrawingBrush>
                <DrawingBrush.Drawing>
                    <GeometryDrawing Brush="Aqua">
                        <GeometryDrawing.Pen>
                            <!-- ペン幅1ピクセル指定にもかかわらずスケーリングされて太くなる -->
                            <Pen Brush="Red" Thickness="1" />
                        </GeometryDrawing.Pen>
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0, 0, 10, 10" />
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingBrush.Drawing>
            </DrawingBrush>
        </Rectangle.Fill>
    </Rectangle>
    <!-- 以下のように記述するとスケーリングされない -->
    <!--<Rectangle
        Stroke="Black" StrokeThickness="3 Fill="Aqua">
    </Rectangle>-->
</Window>