Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Docking controls in WPF

Posted on 2010-09-05
15
Medium Priority
?
844 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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