我通常只使用UserControl作为视图,但在这个项目中我认为从中派生一个View类可能会更好,并将其用作视图的“包含”类,以便以后可能会将更多功能注入到View 。 然而,我当时并没有使用Prism,所以我所拥有的奢侈品更少。
我应该保持这种做法,还是简单的UserControl视图足够?
I normally just use UserControl for a view, but during this project I thought it might be better to derive a View class from that, and use that as the 'containing' class for views, to allow me to possibly later inject more functionality into a View. However, I wasn't using Prism then, so I had much fewer luxuries etc. that an established framework brings.
Should I keep this practice, or are plain UserControl views ample enough?
最满意答案
我认为这是您的观点要求的问题。 正如您所说,这种方法使您可以灵活地为View类添加功能,并使其在所有视图中立即可用。
但是,由于View中的焦点通常放在最大化XAML并最小化代码隐藏(这是行为的一个很好的例子),我认为你的共同基础View类方法可能会以某种方式将你推向另一个方向。 无论你在课堂上投入什么,都要尝试通过XAML和行为来实现它。
I think that's a matter of the requirements for your Views. As you said, that approach gives you the flexibility of adding functionality to your View class and having it instantly available in all your Views.
However, as the focus in the View is usually put in maximizing the XAML and minimizing the code-behind (a good example for this are behaviors), I think your common base View class approach might somehow move you in the other direction. Whatever you'd put into that class, try to achieve it through XAML and behaviors.
更多推荐
发布评论