我有一个我使用的解决方案,但它并没有真正为我提供我需要的所有能力。
现在,我将 Grid 控件的背景设置为 VisualBrush,该 VisualBrush 在其 Visual 容器上包含一个椭圆。这使我无法在绘制的正方形后面设置背景颜色(或至少据我所知)。
我使用这些方块作为我的捕捉定位功能的标记。见图。
有没有办法让我保留我的背景图案并设置背景颜色?另一种方法也很受欢迎,因为我觉得我已经对这个方法感兴趣了,因为它(部分)有效。
由于需求:
brush = new VisualBrush();
brush.Stretch = Stretch.Fill;
brush.TileMode = TileMode.Tile;
brush.Viewport = new Rect(0, 0, SnapDistance, SnapDistance);
brush.ViewportUnits = BrushMappingMode.Absolute;
brush.Viewbox = new Rect(0, 0, SnapDistance, SnapDistance);
brush.ViewboxUnits = BrushMappingMode.Absolute;
ellipse = new Ellipse() { Fill = new SolidColorBrush(Colors.Blue), Width = 2, Height = 2 };
brush.Visual = ellipse;
这就是我为 grid.Background 设置的。我想要做的是绘制我在链接中显示的图案,并且还能够为背景设置颜色,上面带有点图案。