2

网络上似乎有一些是/否/绝对/没有关于此的信息。我希望能够创建一个基类。

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 一起工作,那么请在这里发布一个经过测试的解决方案,我会非常高兴。

4

1 回答 1

1

在 xaml 中使用 x:TypeArguments 可以做到这一点,但众所周知,它会破坏各种 xaml 设计器(在 Visual Studio 和 Blend 中)。

该问题已在 Visual Studio 2012 Xaml 设计器中修复,使用 Visual Studio 2012 Update 2 的最新 CTP。

讨论:

http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/895b38c7-ddde-4d38-8915-493be0efe6a7/

CTP 下载:

http://www.microsoft.com/en-us/download/details.aspx?id=36539

不幸的是,它似乎不适用于最新的 Blend for Visual Studio 2012。

于 2013-02-27T10:46:42.780 回答