开发者

Count the number of displayed VisualBrush visuals

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, Hei开发者_StackOverflowght = 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜