WPF Grid for Window Layout - wpf

The main window of our WPF application consists of 4 regions, arranged as 2x2 tiles. The user must be able to resize these regions. This is not a problem when using a Grid control with GridSplitter elements.
But there is an additional requirement. In the center of window where all the regions meet there has to be a button which can be used to resize the regions too. The user can drag the button around. As a result all regions resize. E.g. if the user drags the button to the left the width of both regions on the left decreases. If the button is dragged to the bottom the height of the top regions increase while the height of the bottom regions decrease.
How can I do this using the WPF technology?

Use a Thumb as the central button, and handle its drag events (DragStarted, DragDelta, DragComplete) to move the GridSplitters at the correct position

Related

Dockable Toolbar

I have an area in my application that contains toolbar, my toolbar is consist of movable canvas, that I can drag and drop it anywhere, what I want to do is to restrict the user and not allow the toolbar to be moved out of this area,
and make it dockable so I can dock it to the left, right, top and bottom of this specified area,
can anyone help me in this case?
bellow snapshot show the toolbar is highlighted by red and the restricted area is highlighted by black this area the user can't move the toolbar out
Here is the snapshot
You can reset the toolbar's position after a drag operation is completed.
First get the toolbar's coordinate which is relative to the Canvas, then translate it to coordinate relative to the bound (black area).
You can then calculate how close the toolbar's center is from each edge of the bound. If the distance is lower than a defined value, move the toolbar to the edge (to dock it), you need to rotate the toolbar 90 degrees if you dock it to the left and right edges.
Something like this.

Aligning components with each other in WPF

A WPF application consists of a uniform grid of arbitrary size. Each cell in the grid contains a canvas. Each canvas is a target for a drag and drop operation.
When I drag another canvas and drop it onto a canvas inside the grid I want the top left corners of the dragged canvas(source) and the target canvas to align, essentially placing the source on top of the target. The behaviour I'm looking for is a snap-to-grid effect.
Currently when I use element.GetValue(Canvas.LeftProperty) the result in NaN. The problem is to determine the position of the corner for a canvas inside the grid, but relative to the entire window. I would prefer to use the grid, as it automatically resize as the window resize.
Is it possible to get the actual position of a canvas inside a grid even when the grid size changed or alternatively specify a canvas to be aligned to another canvas inside the grid?
This problem was solved by drawing each canvas onto another canvas by specifying the top and left properties of the canvas, I had to scratch the grid. I specified the position of every canvas by using
Canvas.SetLeft(Me, position.X)
Canvas.SetTop(Me, position.Y)
where Me is an instance of the canvas.
It is now easy to get the top and left properties of every canvas. The only problem now is I have to implement the resizing of every canvas manually.

How to make a resizeable (from conner) layout like in 3d max main window

I have WPF prototype application which includes 1-4 other controls (WebBrowser control) like on picture
A need to resize a control (with facebook) taking it's conner and reducing size until the center of a window. If the size of this control would be less then "minSize" then it should be hidden\closed. Other layouts should fill an empty area.
I don't know from which controls should I start my experiments. No one does the right work.
I tried Grid, but it's impossible to take cell's conner to resize webBrowser control.
GridSplitter works just for two panels and doesn't let me take cell's conner.
Some developers say about custom control creating...

Windows forms app, autoscale controls with form

I'm a newbie. Designing a form that can be resized, and I want my textboxes, labels and buttons to resize with the form, can someone tell me how to do this?
It depends on the type of layout you need. The "basic tools" you have to do that are following properties: Anchor and Dock.
Anchor
With the Anchor property you "attach" a side of an element to a side of its container. For example if you place a button in the bottom-right corner of a window and you set "Bottom, Right" as Anchor then when you'll resize the form the button will keep its relative position to that corner.
Now imagine you place a multiline text-box in the form, resize as needed (for example 4 px from top, left and right border and 128 px height) and set the Anchor property to "Left, Top, Right". When you'll resize the form that control will keep its height but it'll resize to keep its margins (so if you'll make the form wider its width will be increased).
Dock
Dock is different. With docking you "say" to the Layout Manager to use all available space in one direction. For example if you set to Left then your control will keep its width but it'll use all the available height and its location will be most left as possible.
You may have more than one control docked in a container, imagine you have 5 textbox with Top docking inside a form. They'll be stacked to the top of the form using all the width (and resizing). Another example: a Top docked control (as a banner) and a "Fill" docked control (as main content). Remember that with docking the order of controls matters (if you first place the "Fill" control it'll use ALL the available space and the "Top" dock control will overlap).
Even more
Moreover you have some layout controls too (tables and stacks). They're really easy to use and a 30 minutes of "experiments" will clarify much better than a long text.

Panning the display area in WPF

The application will have a menu strip on top and the rest will display lines and shapes. I want to be able to drag and pan the main display area by clicking it and dragging it in any direction.
I am currently drawing items using pixel values (for example a line drawn from (1042,54)to(1240,104). But I think a monitor with a smaller resolution will not be able to display that object. That is why I want to be able to pan the display area.
The lines and shapes are currently being drawn on a gird that I placed inside the window.
If you place the canvas inside a ScrollViewer then if the canvas is larger than the application window it will be displayed with scroll bars.
You can then address points on the canvas with values relative to the canvas rather than the screen.

Resources