bradgonesurfing
bradgonesurfing

Reputation: 32162

Is it possible to create a generic base class for user control in XAML for Visual Studio 2012

There seems to be a bit of yes/no/absolutely/no way info floating around on the web about this. I'd like to be able to create a base class.

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!

}

Then create a new concrete user control in the designer based off GenericUserControl

class MyControl : GenericUserControl<MyControlViewModel> {



}

I've seen a number of blog post claiming this is possible using x:TypeArguments in XAML and there seems to be XAML doc http://msdn.microsoft.com/en-us/library/ms750476.aspx suggesting this feature is possible but then again I've found posts saying this feature is broken in Visual Studio 2012.

So if this is possible and any genius can figure out how to get it working specifically with VS 2012 then please post a tested solution here and I will be super happy.

Upvotes: 3

Views: 1337

Answers (1)

&#216;ystein E. Krog
&#216;ystein E. Krog

Reputation: 331

This is possible to do using x:TypeArguments in xaml, but it is known to break the various xaml designers (both inside Visual Studio and Blend).

The problem has been fixed in the Visual Studio 2012 Xaml designer, with the latest CTP of Visual Studio 2012 Update 2.

Discussion:

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

CTP download:

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

Unfortunately it does not seem to work in the latest Blend for Visual Studio 2012.

Upvotes: 2

Related Questions