views:

117

answers:

3

I am adding user controls in my solution. The main page of my project will have a dock panel. When writing the xaml for my user controls should I remove grid and use dock panel or what? Iam using visual studio express and WPF.

A: 

The answer is it depends on what you want your control to look like.

Remember the Grid is to help you orgainze your controls. You can define features like columns widths, row heights, and other styling.

While a dock panel is to help dock your control to a part of the form or another.

So it depends on what you want your control to look like. You can nest a grid in a dock panel and vice versa. There is no set rule. It is really up to you.

David Basarab
A: 

Inside your user controls, use whatever type of panel makes sense for the contents of that control. In the main page, you set the DockPanel.Dock attribute on your user control, but that is independent of what's inside the user control.

Eddie Deyo
A: 

It really depends on what you want to do.

Your top level may not even be a panel. For example, if you only want one control in the user control, then you really don’t need the panel.

Also, in some cases, even with composite controls, you may want to put something other than a panel as the top level control, for example, an expander.

Further, if you want to create a control that is very similar to another control, but behaves a little different, you may not even want to use a user control and instead inherit from an existing control. An example of this would be a numeric textbox that inherits from a textbox but adds keypress filtering.

Trent F Guidry