Erasing in a WPF program - wpf

How can I make a MS Paint clone in WPF?
I use Canvas and Shapes, but I don't know how to implement erasing. Should I use different controls, image control for example, or other drawing technology?

You can simply remove the object from the Canvas using canvas.Children.Remove() methods.

Related

Is it technically possible to render a wpf Xaml element to a direct3d texture?

Lets say I have a simple WPF canvas where I draw a few buttons and shapes using xaml. I would like to render the canvas to a direct3d texture so I can have access to the pixels from within the GPU.
RenderTargetBitmap allows me to do software rendering. but this will be limiting in terms of performance as I will have to manually copy the pixels to where I want.
I also looked into using a custom shader effect on the canvas. but as far as I know it is impossible to write to a separate texture using direct3d 9.
So is it at all possible? if so how?

TreeView fontsize - Custom Draw or Owner Draw

I want to change the font size of a TreeView control. After searching on goolge, I just get some idea that one should use CustomDraw for this TreeView. But NMTVCUSTOMDRAW structure only has clrText and clrText which set the foreground and background color of the displayed texts in TreeView.
My questions are:
Q1: How to change the font size in a TreeView? For the background color of TreeView,
one can just use `TreeView_SetBkColor` or send a message. Anything similar
for font size?
Q2: What's the difference between Custom Draw and Owner Draw?
Q1. You can do this with the WM_SETFONT message.
Q2. They do similar things. Owner draw is an older system and means you have to draw the entire control yourself. Custom draw is newer and more flexible, letting you handle just parts of the drawing if you like (or even no drawing, and just changing fonts/colors).

Drawing shapes, text and images with moving and scaling in WPF

I'm trying to draw simple map in WPF. I need to draw shapes, text and images. It also should be possible to use mouse to move around and zoom in and out.
Right now, I have combination of Canvas + Geometry + Transforms to draw shapes, but I don't know how to add text and images.
I already tried various combination of Canvas/Grid and Layout/Render transform. Biggest problem is adding text and images, because transformations are in geometries.
If i understand you right, you're currently putting Path objects (with transformed Geometries) into a Canvas. For adding text and images you could easily add TextBlock and Image objects to the same Canvas and apply your transformations to their RenderTransform property.
A completely different approach would be to use WPF low-level rendering, provided by the DrawingVisual class. You may start at WPF Graphics Rendering Overview.

Programmatically draw a bitmap to a WPF Canvas?

How can I programmatically draw a bitmap to a WPF Canvas? (or should I do something else entirely?) I will have about 40 moving images.
If you need to dynamically create and modify bitmaps, then use a WritableBitmap. You can place these on a canvas.
I did something similar, but I wanted some logic on each image(object) so I created a UserControl with an image and just add the UserControl to the canvas.

WPF: is it possible to have a content container move 3d dimenisional in a modelvisual3d element?

i was learning 3d animation in wpf.. and most tutorials would make an image 3d then play with it alittle ..moving and changing dimensions..
so it got me wondering.. is it possible to add some type of data container (like a grid canvas.. or whatever).. and make it move in 3d dimensons too ?
i am not talking about skewing.. i am talking about real 3d movement..
What a lot of examples do in .Net3.0 is use visual brush to draw the visual of the control/data container on a surface in 3D space. And then map the mouse and keyboard events back to the 2D control (through a translation).
They are a lot of examples that illustrate this. (one for instance is)
An alternative is to use a panel that layouts your control in 3D space using one of the thriple opensource project Or you could read the code (since it's opensource) as a starting point.

Resources