网络上似乎有关于这个问题的一些肯定/否定/绝对不可能的信息。我想创建一个基础类。
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中具体运行它的方法,请在这里发布一个已测试的解决方案,我会非常高兴。