Resizing controls on a canvas - silverlight

I have a Silverlight (v3) application that users can drag controls (e.g. Shapes, Images) onto, change the fill colour, drag around etc
I am looking for the best method to allow the user to click on a control, give a visible indication that the control can be reiszed (e.g. display resize handles) and then handle the resizing.
I have played with a few ways of doing this but I am not sure of the best way to make this as clean/generic as possible - ideally I would like to mark a control as resizable and then have common code implement this. I have tried 1) adding a ControlTemplate to a control and 2) handling the MouseLeftButtonDown event and adding a new rectangle which surrounds the object and then resizing the original control as this rectangle is resized.
Does anyone have experience of implementing this, some good code resources?

Have a look at this Resize Behavior

Related

Making a custom(/templated) ScrollViewer or ListBox that understands which item to bring to view

I am trying to make a panorama-like control in WPF c# that scrolls to/brings into view only one grid from a horizontal set of grids. I need to expose the command which allows me to scroll forward/backward from various controls (which using an InteractionTrigger would suffice) on any of the grids in the ScrollViewer or ListBox.
I want each of the internal grids to size to the actual height/width of the usercontrol they live in (like tiled pages), won't need any scrollbars, and will eventually be applying easing effects/states to each of the scroll positions.
If this is too vague/convoluted, please let me know.
Thanks in advance! :)
Easy Solution:
PathListBox. Downloaded the PathListBox toolkit (for the PathListBoxScrollBehavior), set the capacity to 1, and used the templated InteractionTriggers to bind various source objects on my grids to the InvokeCommandAction Increment/Decrement Commands. Then I added easing effects/GoToStateActions.
I realize this is sort of a cheat, but am still going to search for the "real" way to do this with custom control templates deriving from ListBox and/or ScrollViewer.

Transparent overlay which does not scroll with its parent

I would like to have a form which has a few controls as transparent overlays over a bitmap. This bitmap is subject to transform matrix (zoom & scroll). I'm trying to achieve a look similar to GoogleMaps where the controls do not move when the background image is panned/zoomed.
I've tried to mimic this in my OnPaint. However, when the window is scrolled only the newly exposed area gets invalidated so my control doesn’t repaint.
I've tried to calculate where the old control was, invalidate that area, and also invalidate the area where it's supposed to have been. When I do this it flickers and you can still see the image as its scrolled.
I tried to put a ButtonControl on my display window. However, it always scrolls with its parent control. I tried to capture the scroll events and then adjust the position of the ButtonControl. This also has a delay update effect so it looks not so good.
Any ideas would be greatly appreciated.
It sounds to me like you need to Invalidate() your control wich handles the OnPaint event.
Unfortunately, you get the flicker because the Auto-scrolling mechanism sets its position, and then you restore it. The result is two messages being sent to the button.
Place your bitmap and scroll logic in a separate control that fill the entire form. That means both your bitmap control and the button are child controls of the form.
Alternatively, draw the button yourself. You will then of course need to do some work on getting it to respond to mouse clicks etc. The ControlPaint class has methods that help you mimic the appearance of Windows controls.

Is it possible for WinForm controls (Panel,etc.) to grow like a webform control?

I'm converting an app from ASP.NET WebForms to WinForms. There is one asp.net page which contains a ListView/Repeater that contains several custom controls, which in turn contain a ListView with other custom controls. Basically the layout looks like a TreeView, but on each node/leaf there are few controls like comboboxes, etc.
When this is in ASP.NET, the page automatically lays itself out, so it is several screens tall - if I add 20 buttons into a Panel, it will grow and the browser will get scrollbars.
I'd like to do the same thing in a WinForms application - so I'll have a user control that will contain a lot of controls in a some variation of Panel (Flow, Table layout), and the controls might have another controls inside them, etc.
The problem is, that when I make winforms app, each control has specific height in the design time. I'd like some user controls to be able to grow with their contents - so they'll add up. In the main Form, there should be a vertical scrollbar, just like in the web browser when the generated page is taller than the screen.
I'd just like to get some general pointers in the right direction. Thanks.
Use Anchor and Dock container properties.
Yes, to expound on Anchor and Dock...try this
-Place a Panel on an empty form, and set its dock property to Top
-place a textbox in the panel, and Dock it to Full...it should fill the whole top panel
-Place a splitter on the form, and if not already docked correctly, set its dock to top
-place another panel below the splitter, and set its Dock to Fill
-place another textbox inside the lower panel and fill it as as well
Now you have a form with two resiable textboxes and will resize when the form does.
*you may have to set the textbox MultiLine property to true but not sure.
Hope this helps.
Anchor the controls to the parent. Anchoring all four sides will cause it to stretch.
If the Anchoring and Docking answers don't work for you, there is another option. It's not pretty, but you can access a control's properties and change them dynamically during runtime. You'd do something like: if(listBox.Items.Count > [yourVal]) listBox.height = [yourFormula] or something.
It's been a while since I've done a Win Form (and I don't have my IDE fired up at the moment) but I'm pretty sure there's even a ScrollPanel or other scrolling control that you can set on your form.
That said, when you're working with WinForms, the less scrolling you can make your users do, the better.

silverlight 3: How to create a resizable childwindow?

Is there any way to create a resizable childwindow in silverlight 3? Any pointers are highly appreciated.
I don't have any actual code for you, but you would probably want to subclass ChildWindow and handle the MouseLeftButtonDown, MouseMove, and MouseLeftButtonUp mouse events within a certain "border" of the edge of the ChildWindow or within a certain "grip" region (such as the lower-right corner).
You would want to use some standard drag and drop logic to detect that a drag is being performed for a resize and update this.Width and this.Height based on the relative mouse coordinates using the GetPosition() method of the MouseEventArgs class.
You might also want to have a look at the FloatableWindow control on CodePlex, which is a refactored version of the ChildWindow which supports drag and drop moving and resizing.
Take a look at Tim Huer's FloatableWindow. I think this might do what you are looking for.
http://timheuer.com/blog/archive/2009/07/08/silverlight-floatablewindow-updated-with-resizing-capabilities.aspx

How do you get WPF to work like Forms at design time?

A bit new with WPF...It seems like not matter what I change with horizontal and vertical alignment, WPF has a mind of its own when resizing my controls in design time. I created a new Window, placed a couple of buttons and text boxes and whenever i change the size of the window all the controls get resized. Is there a way to lock it down or am I missing something obvious?
The layout you are using might be a Grid. Try replacing that with a Canvas and you will get the similar behavior as win forms design.
Suggestion: When we use WPF the adavantage we can get is the resizability and be able to dynamically arrange(Change) controls inside a layout etc.. So Try using dynamic layouts than static layouts like "Canvas"

Resources