计算显示的 VisualBrush 视觉效果的数量
我正在 WPF 中开发 CAD 程序,并且正在寻找一种方法来计算渲染特定画笔时显示的控件数量。
假设我有一个椭圆
:
<椭圆x:名称=“椭圆”Canvas.Top=“25”Canvas.Left=“50”宽度=“400”高度=“250”描边=“深蓝色”StrokeThickness=“5”/>
我用后面代码中的 VisualBrush
填充它:
VisualBrush tileCounter = new VisualBrush();
Rectangle rect = new Rectangle() { Width = 10, Height = 10, Fill = Brushes.Blue, Stroke = Brushes.BlueViolet, StrokeThickness = 1 };
tileCounter.Visual = rect;
tileCounter.TileMode = TileMode.Tile;
tileCounter.Stretch = Stretch.None;
tileCounter.Viewport = new Rect(0, 0, 10, 10);
tileCounter.ViewportUnits = BrushMappingMode.Absolute;
Ellipse.Fill = tileCounter;
有没有办法让 VisualBrush
报告它已渲染的矩形形状的实例数作为椭圆
的填充?或者是否可以进行代码更改,以使用 Fill
或 Background
从父级单独引用每个视觉效果?
我目前正在开发一个工具来绘制具有任意数量边的图形,这些边是 LineSegment
、ArcSegment
或 QuadraticBezierSegment
并且画笔是用户使用输入的高度、宽度和网格大小定义的网格。用户还可以重新调整网格。这使得简单的数学解决方案极难实现,因此 WPF 解决方案会更好。
我的最终目标是获取它尝试渲染的视觉效果总数,然后获取整个填充中每个视觉效果的渲染量。
I am working on a CAD program in WPF and I'm looking for a way to count the number of controls displayed when a particular brush is rendered.
So say I have an Ellipse
:
<Ellipse x:Name="Ellipse" Canvas.Top="25" Canvas.Left="50" Width="400" Height="250" Stroke="DarkBlue" StrokeThickness="5" />
And I fill it with a VisualBrush
from code behind:
VisualBrush tileCounter = new VisualBrush();
Rectangle rect = new Rectangle() { Width = 10, Height = 10, Fill = Brushes.Blue, Stroke = Brushes.BlueViolet, StrokeThickness = 1 };
tileCounter.Visual = rect;
tileCounter.TileMode = TileMode.Tile;
tileCounter.Stretch = Stretch.None;
tileCounter.Viewport = new Rect(0, 0, 10, 10);
tileCounter.ViewportUnits = BrushMappingMode.Absolute;
Ellipse.Fill = tileCounter;
Is there any way to get the VisualBrush
to report back how many instances of the rectangle shape it has rendered as the fill of the Ellipse
? Or are there code changes I could make to reference each visual individually from the parent using the Fill
or Background
?
I am currently working on a tool to draw figures that have any number of sides that are LineSegment
, ArcSegment
, or QuadraticBezierSegment
and the brush is a grid that the user defines with entered hight, width, and grid size. The grid is also able to be realigned by the user. This makes simple mathematical solutions extremely hard to pull off and so a WPF solution would be preferable.
My ultimate goal is to get total number of visuals it attempts to render and then how much of each visual is rendered across the entire fill.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很遗憾地告诉你,但我认为你必须走数学路线。
虽然我不完全同意,但我确信我会假设 wpf 绘制该 rect 一次,然后缓存结果,否则该 Visualbrush 将无法执行。所以本质上它实际上只是一个纹理,你无法知道已经完全或部分绘制了多少块瓷砖。
I'm sorry to tell you but I think you have to go the mathematical route.
Though I'm not entirely, sure I'd assume wpf is drawing that
rect
once and then caching the result, otherwise that visualbrush would not be performant. So essentially it really is only a texture, nothing where you could be aware of how many tiles have been drawn entirely or partially.