Lightweight WPF Template Form

I use ellipses and other shapes as screen markers; I would like others to be able to modify these images using templates. However, since the form does not support templating, I am forced to create a basic UserControl, which displays an ellipse by default, and then uses it instead of the main form.

Has anyone got a tidier solution? I am a little worried that I am creating 1000 of these screens that the performance / memory will be a bit overhead.

+3
source share
1 answer

UserControlcomes from ContentControl. It doesn’t sound like you need content (the ability to place additional controls inside your figure), so I will continue to climb the hierarchy ...

Here's a breakdown of the pedigree:

UserControl
    ContentControl
        Control
            FrameworkElement
                UIElement
                    Visual
                        ...

Controldefines Template, therefore, I believe that the easiest way to achieve what you want is to use Control:

<Control Style="{StaticResource MyStyle}"/>

... and use Styleto install the template and any / etc triggers you need.

If you need to place a child inside your shape, you should use ContentControlthis way:

<ContentControl Style="{StaticResource MyStyle}"/>

If you find this approach is too heavy at runtime, you can use Shape .

Shape
    FrameworkElement
        UIElement
            Visual
                ...

Shape Control, FrameworkElement. . , , , DefiningGeometry. , Control, , .

, DrawingVisual. MSDN:

DrawingVisual - , , . , , .

, , .

+3

Source: https://habr.com/ru/post/1703481/


All Articles