WPF InkCanvas Z-Index for strokes - wpf

In WPF InkCanvas, ink is rendered on top and strokes don't have z-index property. I have other UIElements like shape, images on InkCanvas and can't bring UIElements to top. Is there any work around for this problem. I have tried
below things.
1) use two different InkCanvas (one for strokes & one for UIElements)
- Can't achieve sandwich effect in this (i.e. UIElement between strokes
Something like this in this circle is UIElement
2) Masking strokes using geometry path and add as UIElement
- If I add strokes as UIElements (using path) then I will loose erase functionality.

The map editor which is part of our game suite uses ink to draw terrain so I have recent experience of this sort of thing.
The way my app works is you select a thing you're drawing ( woods, road, contour etc ) and draw a stroke using ink.
I then process that stroke and obtain a geometry.
I pass that to a viewmodel > itemssource > itemscontrol.
This is then templated into a piece of terrain.
This itemscontrol is below the inkcanvas.
The user can manipulate the z-index of those by moving them up and down in the observablecollection.
I rely on just the order to define z-index.
I also retain the data from each stroke by serialising it.
You're thinking "how about erase?".
To do that I'd have an explicit erase-this-thing mode.
Let them pick a shape and get it's stroke data, add the stroke back to the inkcanvas. Once they finish erasing then use a "save changes" button or something to re-process the stroke(s) and switch back to edit mode.
Since this is a game map editor I'm working on, drawing produces area and line types of terrain but their area/line is defined by a geometry translated from a stroke. ZIndex corresponds to the order of objects in the left panel. The buttons you can see with the chevrons pointing up and down move the order of a

Related

WPF Canvas and DrawingVisuals disappear

I have a set of User Controls, derived from FrameworkElement. Each host one or more DrawingVisuals. These drawing visuals can represent text, graphics, progress meters etc and are used to display the states of various HMI devices.
These, appearance-wise work fine in a grid - images are rendered, text and backgrounds appear fine, dependency properties can be set. However, when I encapsulate them in a Canvas, they disappear all but for the drawing visuals representing labels. And even for these, only the text rendered by DrawingContext.DrawText is visible. Operations performed by dc.DrawImage, cd.DrawRectangle etc do not appear.
Can someone please shed some light on why this might be.
Thanks
Are you positioning your controls properly? In a grid you have margins for each item, where as in a canvas you have to set Canvas.Top and Canvas.Left for each element. Is it not that those items are hidden underneath something? Try using snoop to use if the controls are actually part of Canvas children or if they have not been added at all.
You can read more about Canvas on MSDN

How to display a background control in transparent overlapping control?

I'm building a form with two layers of controls. The bottom layer is a set of Panels with defined properties, one of which is a color different from the form background. The top layer is a set of picture boxes I'm using to display a circle. I've set the PictureBox Background to Color.Transparent, and I've offset it from the underlying Panel by one pixel to get the form to draw the underlying Panel. However, the area around the circle in the PictureBox is displaying the Form Background color, not the panel color. I don't want to draw the circle in the Panel, because I want the circles to move between Panels, and actually look like just a circle that's floating across the form independent of the Panel board underneath. Think of the effect as moving a piece on a board game (you see the peg move across the board, possibly on a diagonal not following the normal game path, then stop in a place on the game).
How can I get the PictureBox to have the underlying Form and panels show through, not just the form background color? I'm using C# Visual Studio 2010, and I'm not a terribly experienced programmer, so a code example would be helpful. An image of the form is at:
http://www.imageurlhost.com/images/salgmpcxvcz830c3flt.jpg
Found a way around the problem. I got rid of the Panels for the spaces in the game, and instead drew them as rectangles on the form's background image.

How to do Free hand Image Cropping in WPF?

all
I m developing on Medical Image Processing software, I wont crop image on mouse event, means when we drag mouse cursor and move over the image in any shape, the selected portion of image should be cropped. and that will paste in same image. is it Possible in WPF or Silverlight?
Check out the Clip property. You can specify a path in this property that is used to clip the parent object. Set Clip on your Image control to clip the image.
For design time clipping, your best bet is to use Blend (download a trial here if you don't have it) to draw a free hand path. Right click on the path and select Path->Make Clipping Path. In the next dialog, select the image that you want to clip.
EDIT: It sounds like you want to use runtime clipping/cropping, so you will want to generate the clip path using the points gathered from the mouse events. Create a collection of these points and then generate a path from them (linear lines probably... I don't know how you would generate appropriate curves unless you wrote a complex algorithm). Set this path to the Clip property after the fact.
/EDIT
You can add a transparent layer on top of the control and add an InkCanvas.
Then allow the user to draw a stroke (freehand) and turn the stroke into a Geometry by using GetGeometry use the geometry in the Clip property of the control to be clipped.

Custom Fill Property on PathGeometry in Silverlight

I've been looking at (and getting confused by) Dependency Properties - I'm not sure if this is what I need or if there is something else.
I'm looking to something very specific with <Path.Data/> children in Silverlight, in particular <PathGeometry/>, <EllipseGeometry/>, etc. While the <Path/> element has a .Fill property, I'd like to add a .Fill property to any of it's Geometries, meaning it's a different color from it's parent. It could be a <SolidColorBrush/> or <LinearGradientBrush/> color, or a percentage of the parent color (like 20% darker than <Path.Fill/>.
Is this possible? Is this a dependency property? How would <RectangleGeometry/>, for example, know that I am trying to fill it with a color? How would I get started?
(adding WPF as a tag too as someone who knows WPF may be able to help)
Not its not possible, the stroke and fill brush are properties of the Path shape.
If you want to draw Rectangle, Ellipse etc shapes with their own independent Stroke and Fill properties you need to use Rectangle and Ellipse which are Shape objects in their own right.

WPF VisualBrush with mixed aspect ratio

We are using the Mindfusion WPF Diagramming Component. I require a Visualbrush which must be able to be used in a third-party component for diagramming.
We have horizontally-stretching lanes on the diagramming canvas. We must define a background color for this lane, and some text on the top-left corner, to be repeated on the x-axis. The text must remain the same size while the rest of the lane is filled with color when the lane is re-sized.
Unfortunately, the only thing we can do is provide a Visualbrush to the diagramming component, which is then set as background for the lane. It seems impossible to work with this restriction because I am unable to define a text with fixed size, repeating on the x-axis, while also having a color brush stretching, all within a single Visualbrush. How can this be done?

Resources