在为我的用户控件编写xaml时,我应该删除网格并使用停靠面板或其他东西吗?

时间:2022-07-06 20:15:31

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.

我在我的解决方案中添加用户控件。我项目的主页面将有一个停靠面板。为我的用户控件编写xaml时,我应该删除网格并使用停靠面板或什么?我使用visual studio express和WPF。

3 个解决方案

#1


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.

请记住Grid是帮助您管理控件的。您可以定义列宽,行高和其他样式等功能。

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.

所以这取决于你希望你的控件看起来像什么。您可以将网格嵌套在停靠面板中,反之亦然。没有固定的规则。这真的取决于你。

#2


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.

在用户控件中,使用对该控件的内容有意义的任何类型的面板。在主页面中,您可以在用户控件上设置DockPanel.Dock属性,但这与用户控件内部的内容无关。

#3


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.

此外,如果要创建与另一个控件非常相似的控件,但行为稍有不同,您可能甚至不想使用用户控件,而是从现有控件继承。一个例子是一个数字文本框,它继承自文本框但添加了按键过滤。

#1


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.

请记住Grid是帮助您管理控件的。您可以定义列宽,行高和其他样式等功能。

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.

所以这取决于你希望你的控件看起来像什么。您可以将网格嵌套在停靠面板中,反之亦然。没有固定的规则。这真的取决于你。

#2


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.

在用户控件中,使用对该控件的内容有意义的任何类型的面板。在主页面中,您可以在用户控件上设置DockPanel.Dock属性,但这与用户控件内部的内容无关。

#3


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.

此外,如果要创建与另一个控件非常相似的控件,但行为稍有不同,您可能甚至不想使用用户控件,而是从现有控件继承。一个例子是一个数字文本框,它继承自文本框但添加了按键过滤。