简体   繁体   English

C#-可重用菜单的自定义控件或用户控件?

[英]C# - Custom Control or User Control for a reusable menu?

In my current system the menu is generated via a CustomControl code, which is shared by others project to generate menu as well. 在我当前的系统中,菜单是通过CustomControl代码生成的,该代码也与其他项目共享以生成菜单。 Currently i need to add some functionality to it so that when the scree size shrunk it would be reworked into a design more suited for smaller screen ie mobile. 目前,我需要为其添加一些功能,以便在缩小屏幕尺寸时,可以将其重新设计为更适合较小屏幕(例如移动设备)的设计。

I have worked out how should i make the changes work, however, i found that having html code generated via CustomControl might not be that easy to maintain. 我已经解决了如何使更改生效,但是,我发现通过CustomControl生成html代码可能不太容易维护。 For one, the person who's going to change it would need to know what it is doing and need to have the knowledge on the lifecycle of it as well. 对于一个人来说,要更改它的人将需要知道它在做什么,并且还需要了解它的生命周期。

I'm thinking whether i should refactor the CustomControl into a UserControl, but having read the different between them, it seems that CustomControl is actually more suited since this menu system is being shared across multiple application. 我在考虑是否应该将CustomControl重构为UserControl,但是阅读了它们之间的区别之后,看来CustomControl实际上更适合,因为该菜单系统已在多个应用程序之间共享。

So what do you guys think? 那么你们怎么看? Is having it generated by CustomControl a bad practice (since it makes it more difficult to maintain)? 由CustomControl生成它是否是一种不好的做法(因为它使维护变得更加困难)? If i use UserControl is that a way to cut down the code duplication for it? 如果我使用UserControl是一种减少代码重复的方法?

Thanks 谢谢

If the control is tied to the application, I'd opt for UserControl , since as you stated, it's easier to visualize, edit, and maintain. 如果控件绑定到应用程序,则我选择UserControl ,因为正如您所说,它更易于可视化,编辑和维护。

if you need to use it across several projects, or it needs to be highly programmable/customizable, then I'd opt for a server control. 如果您需要在多个项目中使用它,或者它需要高度可编程/可自定义,那么我将选择服务器控件。

I wouldn't consider one or the other bad practice. 我不会考虑任何一种不良做法。 I would choose based on which is simplest to implement and maintain. 我会根据最简单的实施和维护来选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM