代码后面的 UserControl 变得非常大
UserControl behind code getting very large
我有一个媒体控件用户控件(在我的库中,它基本上是一组开发人员可以自定义的 x 按钮。我在用户控件上为每个按钮放置了 4 个以上的依赖属性,以自定义按钮图像、工具提示、命令,可见性等等。问题是后面的代码现在变得非常大。已经超过1000行代码。我这里有没有最佳实践。
在研究库中的用户控件后,我明白不能使用 mvvm 方法,我弄错了吗
这是控件的图片(非常未完成)
这是开发人员用来在他们的视图中创建用户控件的代码:
<myLibrary:MediaControl VerticalAlignment="Bottom"
Title="{Binding Path=FileName}"
PlayTime="{Binding Path=PlayTime}"
StopClickCommand="{Binding Path=StopCommand}"
StopToolTipMessage="This is the stop button!"
RewindClickCommand="{Binding Path=RewindCommand}"
PlayClickCommand="{Binding Path=PlayCommand}"
PauseClickCommand="{Binding Path=PauseCommand}"/>
DataGrid
class 包含 8678 行代码。
Grid
class 包含 3393 行代码。
MediaElement
class 包含 985 行代码。
你应该知道如何把东西分开,把相关的东西放在一起。
例如,如果你看到DataGrid
的代码,你会看到它如何使用许多更小的助手classes。所以,你应该看看这些控件和其他控件是如何工作的,这是最好的方法。
我强烈推荐 ILSPY tool 查看 .net classes 的源代码。
在线查看源代码
我有一个媒体控件用户控件(在我的库中,它基本上是一组开发人员可以自定义的 x 按钮。我在用户控件上为每个按钮放置了 4 个以上的依赖属性,以自定义按钮图像、工具提示、命令,可见性等等。问题是后面的代码现在变得非常大。已经超过1000行代码。我这里有没有最佳实践。
在研究库中的用户控件后,我明白不能使用 mvvm 方法,我弄错了吗
这是控件的图片(非常未完成)
这是开发人员用来在他们的视图中创建用户控件的代码:
<myLibrary:MediaControl VerticalAlignment="Bottom"
Title="{Binding Path=FileName}"
PlayTime="{Binding Path=PlayTime}"
StopClickCommand="{Binding Path=StopCommand}"
StopToolTipMessage="This is the stop button!"
RewindClickCommand="{Binding Path=RewindCommand}"
PlayClickCommand="{Binding Path=PlayCommand}"
PauseClickCommand="{Binding Path=PauseCommand}"/>
DataGrid
class 包含 8678 行代码。
Grid
class 包含 3393 行代码。
MediaElement
class 包含 985 行代码。
你应该知道如何把东西分开,把相关的东西放在一起。
例如,如果你看到DataGrid
的代码,你会看到它如何使用许多更小的助手classes。所以,你应该看看这些控件和其他控件是如何工作的,这是最好的方法。
我强烈推荐 ILSPY tool 查看 .net classes 的源代码。
在线查看源代码