网络上似乎有一些是/否/绝对/没有关于此的信息。我希望能够创建一个基类。
class GenericUserControl<T> : UserControl {
// Lots of cools stuff based on T cause I wanna! In fact T
// will be the ViewModelClass but please no pedantic discussion on what
// MVVM is or is not. I want generics in XAML!
}
然后在基于 GenericUserControl 的设计器中创建一个新的具体用户控件
class MyControl : GenericUserControl<MyControlViewModel> {
}
我已经看到许多博客文章声称这可以在 XAML 中使用 x:TypeArguments 并且似乎有 XAML 文档http://msdn.microsoft.com/en-us/library/ms750476.aspx表明此功能是可能的但是我又一次发现帖子说这个功能在 Visual Studio 2012 中被破坏了。
因此,如果这是可能的并且任何天才都可以弄清楚如何让它专门与 VS 2012 一起工作,那么请在这里发布一个经过测试的解决方案,我会非常高兴。