设置InkCanvas背景绘制刷通过c#

本文关键字:绘制 InkCanvas 背景 设置 | 更新日期: 2023-09-27 17:49:24

我想通过c#设置以下XAML属性:

<InkCanvas.Background>
                <DrawingBrush Stretch="None" TileMode="Tile" Viewport="0,0,2,2" ViewportUnits="Absolute">
                    <DrawingBrush.Drawing>
                        <DrawingGroup>
                            <GeometryDrawing Brush="White">
                                <GeometryDrawing.Geometry>
                                    <RectangleGeometry Rect="0,0,2,2" />
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                            <GeometryDrawing Brush="#FFE3E3E3">
                                <GeometryDrawing.Geometry>
                                    <GeometryGroup>
                                        <RectangleGeometry Rect="0,0,1,1" />
                                        <RectangleGeometry Rect="1,1,1,1" />
                                    </GeometryGroup>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                        </DrawingGroup>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </InkCanvas.Background>

我该怎么做呢?

设置InkCanvas背景绘制刷通过c#

我已经找到了自己的解决方案,把它留给其他面临同样问题的人。

http://www.c-sharpcorner.com/uploadfile/mahesh/wpf-drawing-brush/差不多就是我要找的了