Solved

Docking controls in WPF

Posted on 2010-09-05
15
822 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Dialogbox API leak? 18 62
windbg taking it's time 32 54
Windows Service to Receive TCP Packets 4 45
Hide Tab Page 3 19
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 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

22 Experts available now in Live!

Get 1:1 Help Now