何时使用自定义用户控件

时间:2020-12-08 16:03:40

I've got a massive UI that I'm designing. The way that my employer wants it, there are at least 100 labels. Now, I've always thought that in cases like this, breaking up the UI into smaller custom controls was the ideal way to go. However, someone recently told me that custom controls are really only for code re-use. What is the actual suggested practice for this?

我有一个我正在设计的大量用户界面。我的雇主想要它的方式,至少有100个标签。现在,我一直认为在这样的情况下,将UI分解为更小的自定义控件是理想的方法。但是,有人最近告诉我,自定义控件实际上只用于代码重用。对此实际建议的做法是什么?

EDIT

The finished form will look like this:

完成的表单将如下所示:

何时使用自定义用户控件

Now, I'm using WPF for the UI, and I'm thinking of breaking this down into smaller bits.

现在,我正在使用WPF作为UI,我正在考虑将其分解为更小的位。

5 个解决方案

#1


2  

Based on your image i see some repetitions, each of this repetitions could be a custom UserControl

根据你的图像我看到一些重复,每个重复可以是一个自定义UserControl

But it depends on the usability is it easier to write a custom UserControl so do it but if it would reduce the readability of your code and it also adds additional complexity don't do it

但这取决于可用性是否更容易编写自定义UserControl所以这样做但是如果它会降低代码的可读性并且它还增加了额外的复杂性而不是这样做

here are an example of what could be separate UserControl's

这里有一个可以单独的UserControl的例子

the green ones are possible useful encapsulations of logic
the orange ones maybe need some not market stuff (don't know enough about your software)
the red ones are the maybe's based on the intern use (from the visual part they are repetitions so the should custom UserControl)

绿色的可能是有用的逻辑封装橙色的可能需要一些不市场的东西(不太了解你的软件)红色的可能是基于实习使用(从视觉部分他们是重复所以应该自定义UserControl)

何时使用自定义用户控件

#2


0  

Since your UI is read-only, I'd suggest using a grid.

由于您的UI是只读的,我建议使用网格。

#3


0  

Are you new to WPF? To break the View into bits WPF offers you CustomControls and UserControls. They are two very similar things yet completely different from each other. CustomControls are Buttons, Labels, TextBoxes, DataGrids...etc. They are basically simple stand-alone controls. UserControls are groups of stand-alone controls serving a purpose such as example a Button and a ComboBox next to each other so user can select something in ComboBox and confirm that by clicking the Button.

你是WPF新手吗?要将视图分成多个位,WPF会为您提供CustomControls和UserControls。它们是两个非常相似的东西,但彼此完全不同。 CustomControls是Buttons,Labels,TextBoxes,DataGrids等。它们基本上是简单的独立控件。 UserControls是一组独立控件,用于实现一个目的,例如Button和ComboBox彼此相邻,因此用户可以在ComboBox中选择一些内容并通过单击Button来确认。

If you wish to display data from database I suggest you DataGrid which will give you a table-alike look with rows and columns and all that. If you wish to place few buttons next to DataGrid on which the user may click to insert a new row or to edit a certain cell then I suggest you to wrap all that with a UserControl which you can reuse in other places where you have to display and change data from database too.

如果你想显示数据库中的数据,我建议你使用DataGrid,它会给你一个类似于行和列的表格。如果您希望在DataGrid旁边放置几个按钮,用户可以单击这些按钮以插入新行或编辑某个单元格,那么我建议您使用UserControl包装所有这些按钮,您可以在其他需要显示的地方重复使用并从数据库中更改数据。

#4


0  

You should be using a datagrid and can customize its template to render individual cells as Textblock (lighter version of Label) from a rendering perspective. The main difference between Textblock and Label is very minor things such as access keys and disabled state behavior. But from a WPF object hierarchy - Textblocks are much lighter. But besides that point - from your employer perspective - once you have customized the grid template and render them (so as they look as textblocks/labels) - your employer should have no problems.

您应该使用数据网格并可以自定义其模板,以便从渲染角度将单个单元格渲染为Textblock(Label的较轻版本)。 Textblock和Label之间的主要区别是非常小的事情,例如访问键和禁用状态行为。但是从WPF对象层次结构 - Textblocks要轻得多。但除了这一点 - 从雇主的角度来看 - 一旦你定制了网格模板并渲染它们(因为它们看起来像文本块/标签) - 你的雇主应该没有问题。

Also as somebody suggested above - if you want to logically break sections of the UI since they maybe coming from a different table in db - then User controls is the way to go (for maintainability of code)

同样正如上面提到的那样 - 如果你想逻辑地破坏用户界面的各个部分,因为它们可能来自db中的另一个表 - 那么用户控件是要走的路(为了代码的可维护性)

Let me know if you are looking for more technical details or need help further technically.

如果您正在寻找更多技术细节或在技术上需要进一步帮助,请告诉我。

#5


0  

There is nothing wrong in making and using custom controls or user controls or defining some data templates which will be reused depending on how your data is organized.

制作和使用自定义控件或用户控件或定义一些数据模板没有任何问题,这些模板将根据数据的组织方式重复使用。

For sure the UI looks pretty messy and some sort of grid should be used with templates for example where there is similar data. I also have the suggestion and first think about the data and the functionality before starting and let the UI be driven by that. For sure you will the reuse controls/templates. If you think in front on the model and behavior the UI can afterwards more easily changed.

确保UI看起来非常混乱,某些网格应该与模板一起使用,例如存在类似数据的地方。我也有建议,并在开始之前首先考虑数据和功能,并让UI由它驱动。您肯定会重用控件/模板。如果您在模型和行为方面考虑前面的UI可以更容易地改变。

Create your viewmodel correctly, implement the functionality in commands, use bindings, after that the UI will come naturally, reuse controls, use several grids, make the UI more user friendly using several regions, tabs, windows or anything that makes the user more comfortable.

正确创建您的viewmodel,在命令中实现功能,使用绑定,之后UI将自然而然,重用控件,使用多个网格,使用多个区域,标签,窗口或任何使用户更舒适的任何内容,使用户界面更友好。

#1


2  

Based on your image i see some repetitions, each of this repetitions could be a custom UserControl

根据你的图像我看到一些重复,每个重复可以是一个自定义UserControl

But it depends on the usability is it easier to write a custom UserControl so do it but if it would reduce the readability of your code and it also adds additional complexity don't do it

但这取决于可用性是否更容易编写自定义UserControl所以这样做但是如果它会降低代码的可读性并且它还增加了额外的复杂性而不是这样做

here are an example of what could be separate UserControl's

这里有一个可以单独的UserControl的例子

the green ones are possible useful encapsulations of logic
the orange ones maybe need some not market stuff (don't know enough about your software)
the red ones are the maybe's based on the intern use (from the visual part they are repetitions so the should custom UserControl)

绿色的可能是有用的逻辑封装橙色的可能需要一些不市场的东西(不太了解你的软件)红色的可能是基于实习使用(从视觉部分他们是重复所以应该自定义UserControl)

何时使用自定义用户控件

#2


0  

Since your UI is read-only, I'd suggest using a grid.

由于您的UI是只读的,我建议使用网格。

#3


0  

Are you new to WPF? To break the View into bits WPF offers you CustomControls and UserControls. They are two very similar things yet completely different from each other. CustomControls are Buttons, Labels, TextBoxes, DataGrids...etc. They are basically simple stand-alone controls. UserControls are groups of stand-alone controls serving a purpose such as example a Button and a ComboBox next to each other so user can select something in ComboBox and confirm that by clicking the Button.

你是WPF新手吗?要将视图分成多个位,WPF会为您提供CustomControls和UserControls。它们是两个非常相似的东西,但彼此完全不同。 CustomControls是Buttons,Labels,TextBoxes,DataGrids等。它们基本上是简单的独立控件。 UserControls是一组独立控件,用于实现一个目的,例如Button和ComboBox彼此相邻,因此用户可以在ComboBox中选择一些内容并通过单击Button来确认。

If you wish to display data from database I suggest you DataGrid which will give you a table-alike look with rows and columns and all that. If you wish to place few buttons next to DataGrid on which the user may click to insert a new row or to edit a certain cell then I suggest you to wrap all that with a UserControl which you can reuse in other places where you have to display and change data from database too.

如果你想显示数据库中的数据,我建议你使用DataGrid,它会给你一个类似于行和列的表格。如果您希望在DataGrid旁边放置几个按钮,用户可以单击这些按钮以插入新行或编辑某个单元格,那么我建议您使用UserControl包装所有这些按钮,您可以在其他需要显示的地方重复使用并从数据库中更改数据。

#4


0  

You should be using a datagrid and can customize its template to render individual cells as Textblock (lighter version of Label) from a rendering perspective. The main difference between Textblock and Label is very minor things such as access keys and disabled state behavior. But from a WPF object hierarchy - Textblocks are much lighter. But besides that point - from your employer perspective - once you have customized the grid template and render them (so as they look as textblocks/labels) - your employer should have no problems.

您应该使用数据网格并可以自定义其模板,以便从渲染角度将单个单元格渲染为Textblock(Label的较轻版本)。 Textblock和Label之间的主要区别是非常小的事情,例如访问键和禁用状态行为。但是从WPF对象层次结构 - Textblocks要轻得多。但除了这一点 - 从雇主的角度来看 - 一旦你定制了网格模板并渲染它们(因为它们看起来像文本块/标签) - 你的雇主应该没有问题。

Also as somebody suggested above - if you want to logically break sections of the UI since they maybe coming from a different table in db - then User controls is the way to go (for maintainability of code)

同样正如上面提到的那样 - 如果你想逻辑地破坏用户界面的各个部分,因为它们可能来自db中的另一个表 - 那么用户控件是要走的路(为了代码的可维护性)

Let me know if you are looking for more technical details or need help further technically.

如果您正在寻找更多技术细节或在技术上需要进一步帮助,请告诉我。

#5


0  

There is nothing wrong in making and using custom controls or user controls or defining some data templates which will be reused depending on how your data is organized.

制作和使用自定义控件或用户控件或定义一些数据模板没有任何问题,这些模板将根据数据的组织方式重复使用。

For sure the UI looks pretty messy and some sort of grid should be used with templates for example where there is similar data. I also have the suggestion and first think about the data and the functionality before starting and let the UI be driven by that. For sure you will the reuse controls/templates. If you think in front on the model and behavior the UI can afterwards more easily changed.

确保UI看起来非常混乱,某些网格应该与模板一起使用,例如存在类似数据的地方。我也有建议,并在开始之前首先考虑数据和功能,并让UI由它驱动。您肯定会重用控件/模板。如果您在模型和行为方面考虑前面的UI可以更容易地改变。

Create your viewmodel correctly, implement the functionality in commands, use bindings, after that the UI will come naturally, reuse controls, use several grids, make the UI more user friendly using several regions, tabs, windows or anything that makes the user more comfortable.

正确创建您的viewmodel,在命令中实现功能,使用绑定,之后UI将自然而然,重用控件,使用多个网格,使用多个区域,标签,窗口或任何使用户更舒适的任何内容,使用户界面更友好。