Solved

Docking controls in WPF

Posted on 2010-09-05
15
826 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ConsoleSql 1 34
What is Thread.Sleep? 5 44
scanning dentists xray (the small ones) 3 41
Angular - break the dataset in chunks? 7 38
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

947 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now