Docking controls in WPF

I am very new to WPF.

How do you dock controls in WPF?
kylebocaAsked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
Ok, for button set HorizontalAlignment = Right, VerticalAlignment = Bottom, Margin = (10,10)
0
 
Gururaj BadamCommented:
Use DockPanel

<DockPanel>
<TextBlock />
<Button />
</DockPanel>
0
 
kylebocaAuthor Commented:
Apparently you didn't notice that I am brand new to WPF.

Where is the dock panel?

I am used to VS2008
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Gururaj BadamCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
kylebocaAuthor Commented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
I really cannot understand your exact needs. Could you post a couple of screenshots to describe the effect you want?
0
 
kylebocaAuthor Commented:
When a window is maximized I want the controls to follow the form and be in the same relative position.
0
 
Gururaj BadamCommented:
Yes, the DockPanel should be able to do that for you
0
 
Jaime OlivaresSoftware ArchitectCommented:
>>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
 
kylebocaAuthor Commented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
The correct term is Alignment instead of Docking :)
0
 
kylebocaAuthor Commented:
Ahhhh. That looks better. I experimented with the properties and perhaps "stretch" would be best for all the controls on a form?
0
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
kylebocaAuthor Commented:
Thanks Jaime. I will have to experiment with those properties.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.