WPF: how to create complex user controls? (e.g. GDI +)

For example, let's say I want to create something complex. as a circular / stony graph. for example, Google maps or a stock market chart or something like that.

XAML and this whole hierarchy does not work. What I'm trying to do is more like a day ago with GDI + / Winforms. Where can I override the paint, that is, "protected override void OnPaint (PaintEventArgs e)" and then I would do whatever I wanted. Where would I do double buffering. How to draw in the buffer and display it on the screen.

But how do I do this in WPF?

+3
source share
3 answers

WPF GDI/GDI +/WinForms , WPF ( GDI). , ( , ) . / WPF.

/ - , , , , - Visuals. (, ..), , , , , ..

+2

WPF, Ellipse, Rectangle, Canvas, :

var rect = new Rectangle();
//...set width, height...
Canvas.SetTop(rect, 10);
Canvas.SetLeft(rect, 15);

. , , , , ! WPF - :

var rotateTransform1 = new RotateTransform(45);
rect.RenderTransform = rotateTransform1;
+1

, UIElement FrameworkElement OnRender, DrawingContext, , , .

But if you want to work in the philosophy and spirit of WPF, perhaps in 99% of cases you do not need to redefine OnRender. WPF offers many (and I really mean LOT) ways to develop new controls using styles, templates, and if the two do not work, then subclass the corresponding control in the hierarchy of WPF controls.

As gstercken pointed out very well before, WPF is not WinForms, you have to think in WPF to do a good job.

0
source

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


All Articles