Solved

Docking controls in WPF

Posted on 2010-09-05
15
829 Views
Last Modified: 2013-11-12
I am very new to WPF.

How do you dock controls in WPF?
0
Comment
Question by:kyleboca
  • 6
  • 6
  • 3
15 Comments
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33607030
Use DockPanel

<DockPanel>
<TextBlock />
<Button />
</DockPanel>
0
 

Author Comment

by:kyleboca
ID: 33607052
Apparently you didn't notice that I am brand new to WPF.

Where is the dock panel?

I am used to VS2008
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33607112
It's the basic control you should be able to see it in the Toolbox or you can directly type-in

http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.aspx
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 33607764
have you started to play with XAML?
As Novice pointed out, you can use the as a container for child controls.
There are 2 important features in the DockPanel to be usable:
 
<DockPanel LastChildFill="True">
    <Button Content="control 1" DockPanel.Dock="Top"/>
    <Button Content="control 2" DockPanel.Dock="Bottom"/>
    <Button Content="control 3"/>
</DockPanel>

The LastChildFill attribute indicates that the last control in the list will fill all the remaining space of the parent control.
The DockPanel.Dock extension attribute tells the DockPanel to dock the child control in an specific border.
Here is a good tutorial: http://www.wpftutorial.net/DockPanel.html

If you intend to implement dynamic docking, then DockPanel alone wont help you, and the solution is not trivial. Have a look at: http://www.codeproject.com/KB/WPF/WPFdockinglib.aspx
0
 

Author Comment

by:kyleboca
ID: 33608520
Sooooo, in WPF I can't just make a few clicks and dock a control to all sides of a form and when the window is maximized the control will be where it needs to be?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 33608532
I really cannot understand your exact needs. Could you post a couple of screenshots to describe the effect you want?
0
 

Author Comment

by:kyleboca
ID: 33608546
When a window is maximized I want the controls to follow the form and be in the same relative position.
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33609083
Yes, the DockPanel should be able to do that for you
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 33609225
>>When a window is maximized I want the controls to follow the form and be in the same relative position.
Not sure if dockpanel is what you need, you mention "Controls", what kind of controls?
Sound more like you need to manage HorizontalAlignment, VerticalAlignment and Margin properties for every project. With them you can determine relative position of control with respect to top, left, right and bottom margins. Control sizes can be fixed or relative to window size.
have a look to this tutorial: http://msdn.microsoft.com/en-us/library/ms751709.aspx
0
 

Author Comment

by:kyleboca
ID: 33611398
Maybe my terminology is incorrect.

See attached pictures. If I place a button in the Right Lower corner in my form at design time. During runtime and the window is maximized I still need it to be in the Right Lower corner.
Dock1.jpg
docking2.jpg
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 33612193
Ok, for button set HorizontalAlignment = Right, VerticalAlignment = Bottom, Margin = (10,10)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 33612197
The correct term is Alignment instead of Docking :)
0
 

Author Comment

by:kyleboca
ID: 33613153
Ahhhh. That looks better. I experimented with the properties and perhaps "stretch" would be best for all the controls on a form?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 33613170
stretch will resize the control according to parent window, while keeping the current margins. Stretch is not the best choice for your specific example (Button)
0
 

Author Closing Comment

by:kyleboca
ID: 33613200
Thanks Jaime. I will have to experiment with those properties.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question