views:

39

answers:

1

I have this code behind:

CustomUserControl.xaml.cs

namespace MyProject
{
    public partial class CustomUserControl<T> : UserControl
    {
        ...
    }
}

and this xaml:

CustomUserControl.xaml

<UserControl x:Class="MyProject.CustomUserControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Grid>

</Grid>

It doesn't work since the x:Class="MyProject.CustomUserControl" doesn't match the code-behind's generic class definition. Is there some way to make this work?

A: 

Unfortunately XAML does not support generic code behind, thou you can walk around this.

See links below:

http://forums.silverlight.net/forums/p/29051/197576.aspx

http://stackoverflow.com/questions/185349/can-i-specify-a-generic-type-in-xaml

May be generic controls will be supported natively in future versions of Visual Studuo with XAML 2009.

Andrey Gordeyev