Adorners overlap controls that are above the adorned element - c#

Hey, I'm having an issue with adorners. I created resize adorners which have four Thumb controls, one for each of the corners of the control being decorated. The control is being drawn on a Canvas, and the user may select it and resize it.
The canvas is hosted on a ZoomBoxPanel control, which basically applies a ScaleTransform and TranslateTransform to the whole thing to provide zoom and pan support.
Problem is that when an item is outside the bounds of the zoom panel, and the item is cropped as you'd expect (like when you set ClipToBounds = true), you can still see the adorners! Could anyone please tell me a way to prevent this?
Evidence. The black square is the one selected, two resize thumbs are visible (right), the others should not be visible (left)
Thanks!!

Fixed it, solution was to put an AdornerDecorator object immediately above the Canvas :)
<AdornerDecorator>
<Canvas>
</AdornerDecorator>

Related

PictureBox anchor not working properly

On my form I have a Panel control that contains a PictureBox control and a Label control.
The panel is not visible in the image above but it's basically the area around these two controls.
I have set the Anchor property of all these three controls to Top, Bottom, Left, Right so that they follow their parent container's re-sizing behavior.
The L abel control (postbagfolderempty) works properly but the PictureBox (EMPTY!) does not seem to be moving from its original position.
Is there an additional property I need to set?
Update: I changed my PictureBox's AutoSize property to None. It has started to move, but as I try to enlarge my form, it starts sinking into a white area (image below).
Make sure your PictureBox doesn't have SizeMode set to AutoSize.
Anchoring changes the size, if it's autosized it won't change anything
Also, make 100% sure your PictureBox is actually a child of the panel. It's easy to check: select it on the designer and press Esc, it should select the panel.
Update
As per the comments, seems the problem is that you are anchoring to all the sides (thus producing the scaling of the control).
If you want a panel that scales with the form, and controls within the panel that are centered but not scaled along, then anchor that panel to all sides, place the controls inside the panel centered in the designer, and set their anchors to None, that way they won't scale, and since they are not anchored, they will move along when the panel scales (but they won't scale with it, which -seems- it's what you are aiming at)

Group items on a Canvas

I am creating shapes on a wpf using a Canvas. I have created by C# code some Rectangles, each one of which is assigned with three circles and a TextBlock. I want now to make them move on the Canvas by a mouseEvent , in other words to drag them with the mouse and to move them on the Canvas. How is it possible to manipulate each Rectangle with the circles and the TextBlock as a compact group?
It is required, when the user clicks on the Rectangle to transfer it with its contents. However, the circles and the textBlock have their own coordinates, so if not grouped they stand still. How can I get over this?
Put the rectangle and everything else in a grid or another canvas, as described in this related question of yours: Drawing circles on a Rectangle
This is basically a user control composed of the rectangles, circles, and textbox, and you just allow that whole user control to be moved around, rather than the constituent parts.
If you don't want to add another layout panels try to apply the same transform to all elements you want to move, it's not so heavy solution.

Zooming and panning an image canvas

I have a silverlight Canvas which holds an image with drawings on it (polygons). I need to develop a control to zoom and pan this canvas within a work area (Border within a Grid cell, as of now) as shown below. What is the best way to do this. Is there any libraries I can make use of?
I need to be able to add drawings to the zoomed/panned canvas too.
Lots of code examples available on the internet. Check out ZoomControl and CodePlex.
You can try creating a UserControl that is basically an image inside a canvas, and expose two transform properties to control the zooming and panning. A ScaleTransform would handle zooming, and a TranslateTransform would handle panning. You can create a CompositeTransform from both of them and assign that as the RenderTransform of the canvas.
You can bind the zoom slider to the ScaleTransform, and handle mouse events to change the TranslateTransform. As long as you get the mouse coordinates relative to the canvas itself that should work (i.e. mouseEventArgs.GetPosition(canvas)).

How do I get the size of the visible part of a WPF usercontrol?

I have a usercontrol that consists of a label and a textbox. It's inside a scrollviewer.
I'm drawing an adorner on top of it and I need to adjust the size of the adorner to the visible size of the control.
How do I get the visible size of the control?
In the image below the green rectangle is the adorner. As you can see it's being drawn over the scrollbar on the right side.
Is it possible to get the size of the rendered part or will I have to manually go trough the visual tree and calculate it?
edit: more background info
I'm build a very limited form designer. Everything is happening in code. The adorner is used to display the current selected control.
I would put a Canvas in your ScrollViewer and place all of your user controls on the Canvas. If the Adorner is then painted on the Canvas you don't have to worry about it drawing over top your ScrollViewer.
You would also have the added benefit of the adorner disappearing under the ScrollViewer, rather than just ending at it, so your users know that the control extends beyond the ScrollViewer. This is how all of the designers I've made and seen made in WPF work.
If you are only worried about clipping the adorner, then you can include an AdornerDecorator in your content. Something like:
<ScrollViewer>
<AdornerDecorator>
<!-- Your content here -->
</AdornerDecorator>
</ScrollViewer>
Or you can include the AdornerDecorator directly in your UserControl.

How do I stretch the control to fill Canvas in Silverlight?

What I need to do is to stretch the control to fill entire Canvas.
I think I have to use a Canvas (I don't want my control to be clipped
when rendered outside the container - as far as I know all the other containers
perform clipping - Grid, Border... - maybe there is another solution?)
If I put the control inside Canvas it works fine (I mean it is not clipped).
However, it doesn't fill entire Canvas.
I was trying to bind to the Canvas width and height - with no results.
Do you have any ideas or clues?
Thanks in advance!
A control can escape the container such as a Border or a Grid by having negative margins. So perhaps you should return to using a Grid and play around with placement using column and row definitions and using negative margins where you need them.

Categories

Resources