gpt4 book ai didi

c# - 在 Grid 控件上绘制对齐模式

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:52 24 4
gpt4 key购买 nike

我有一个我正在使用的解决方案,但那个解决方案并没有真正为我提供我需要的所有功能。

现在,我将 Grid 控件的背景设置为 VisualBrush,该 VisualBrush 在其 Visual 容器上包含一个椭圆。这使我无法在绘制的正方形后面设置背景颜色(或者至少到目前为止我知道)。

我使用这些方 block 作为我的捕捉定位功能的标记。见图。

http://imgur.com/AtNYp

有没有办法让我既能保留我的背景图案又能设置背景颜色?另一种方法也很受欢迎,因为我觉得我已经对这个方法下了雪,因为它有效(部分)。

由于需求:

  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设置的。我想要做的是绘制我在链接中显示的图案,并且能够为背景设置颜色,上面有点图案。

最佳答案

您可以使用带有捕捉点的 Canvas 覆盖网格,或者您可以使用捕捉点创建装饰层。

引用自MSDN page

Adorners are a special type of FrameworkElement, used to provide visual cues to a user. Among other uses, Adorners can be used to add functional handles to elements or provide state information about a control.

因此控件布局(按 Z 顺序)将是:

  • 网格
  • 带有捕捉点的叠加层(不知道事件将如何处理)
  • 你的元素

  • 网格
    • 装饰层
  • 你的元素

关于c# - 在 Grid 控件上绘制对齐模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7899516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com