Solved

Docking controls in WPF

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

How do you dock controls in WPF?
0
Comment
Question by:kyleboca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…

697 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