Reputation: 3553
There is a windows form application which i am trying to convert to wpf , but when i override onPaintBackground on main window using
protected override void OnPaintBackground(PaintEventArgs pevent)
There is error
no suitable method found to override
so what is the alternative for onPaintBackground in wpf ?.
Upvotes: 2
Views: 806
Reputation: 2201
You really don't want to be doing this with WPF. There are good reasons to override OnRender, but as a replacement for painting the background isn't one of them. WPF is a retained mode graphics system and WinForms is an immediate mode one. You'll want to read up on the differences here:
http://msdn.microsoft.com/en-us/library/ff684178%28v=vs.85%29.aspx
Whereas with WinForms if you wanted to animate a control you first need to clear the area that it was previously rendered in to avoid artifacts, with WPF you just animate the properties you want and let the system handle invalidating the pixels.
Upvotes: 2
Reputation: 50672
In general you shouldn't 'paint' in WPF. Because it can be very slow to continuously recreate the objects (Pens, brushes, shapes).
You can override the OnRender method, example from this page:
protected override void OnRender(DrawingContext dc)
{
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Colors.LimeGreen;
Pen myPen = new Pen(Brushes.Blue, 10);
Rect myRect = new Rect(0, 0, 500, 500);
dc.DrawRectangle(mySolidColorBrush, myPen, myRect);
}
Upvotes: 2