I'm writing a 2D graphics tool in C# and WPF, and I'm using Adorners on the Shapes drawn to Canvas.
I'd like the adorners to highlight when a shape is considered "selected", which I'm currently doing using MouseDown and MouseUp events.
However, the user can select multiple shapes, so not all of the shapes will receive both of the mouse events.
I have a class that manages the drawing, which holds a List of the selected shapes. What is the best way to give the adorners access to this data, so they can see if their adorned element is selected?
Some thing's I've considered:
Making the List global - bad idea
Sub-classing each shape to add a "selected" property - would require changing all references to the shapes in my class
You can make an attached dependencyproperty you set on your shape - then you can set that property when you select one.
The adorner can have a visibility binding to the property on the shape so you get visibility set automatic.
You can also use the Tag property on the shape to store values - that is the old way of doing it :)
Related
I have a canvas where I need to draw a grid, but behind child controls. I tried to create a new adroner and just add it to the canvas, but this adorner is displayed over child controls. How can I make this adorner be behind canvas' children? I don't want to draw this grid in the OnRender function of the canvas...
Clarification: grid is not a control. it is a painted grid or net on the canvas. it is created for making position elements easier.
One way to do this is to use a TileBrush as the Canvas.Background and set the TileBrush to an appropriate grid pattern.
An Adorner can only ever be on top (it allways has the highest zindex). You need to look at another solution to your underlying issue
Use the Panel.ZIndex Property to set the order elements get displayed on the z-plane.
In a WPF application, I'd like to create a textbox dynamically which will show in front of the application and be able to freely set its location by pixel. (The textbox is going to follow the mouse cursor).
This was easily done in Winforms on the fly but WPF makes things.. a little bit weird when it comes to setting a control's location by pixel since I have to add the control as a child of a container. I'm aware this is certainly doable on Canvas, but what I actually have is a dockpanel with a richtextbox to the left and a datagrid to the right.
So what are my options here? Do I have to use canvas? Can I get away with using dockpanel (or grid) to implement what I want here?
You can use a Canvas or a Grid. If you use a Canvas, set the Canvas.Left property and the Canvas.Top property. If you use a Grid, you'll need to set a size for your TextBox, set the HorizontalAlignment to Left, and VerticalAlignment to Top. To change the location of the TextBox, assign it values for MarginLeft and MarginTop.
i have a program in C#, wpf.
i have a canvas and on the canvas exists many ellipses that are moving randomly.
Can i add text to each ellipse for example the position of the ellipse ???
Of course, create a user control. The xaml of that user control is a grid that contains your ellipse and your textbox that you set up like you want. Then define the PropertyChanged notifying properties you need, like X,Y, and maybe other text property. Then bind your user control's xaml (Canvas.Top/.Left) to your user control's properties, and you're done.
I'd like to change the focused node in my TreeListControl via code. For the sake of simplicity, I have this example:
A grid has two columns, left we have a TreeListControl, and at right there is a Canvas.
The TreeListControl is populated with nodes corresponding to some shapes in the Canvas (such as the shapes name, etc.).
What I already have done, is to highlight the shape in the Canvas by selecting the corresponding node in the TreeListControl.
Now what I'd want to do is the other way around: to change the focused node in the TreeListControl by clicking on a shape in the canvas.
Thanks in advance
You should set the TreeListControl's FocusedRow property to the instance of business object. In this case, everything should work properly.
I am working with expression blend and c# to create a silverlight site. I would like to create a map of the world which has many regions. on clicking on the region the colour changes. I have already created the regions.
Does anyone know how to do that?
Thanks
Since you have the regions created already, when you get the click event you need to change the colour of the region. Normally this would be the background property of the control, though it can depend on what control you used to represent a region?
Edit in response to comment
Since you're using rectangle and other shapes Fill is the property you will be changing.