Nicolas
Nicolas

Reputation: 21

Generic Type XAML 2009

I have a litte problems with these class

public class MyClass : MyGenericClass<String, Int32>
{

}

// XAML Class
public class MyGenericClass<T, U> : MyGenericClassBase<T, U>
    where U : class
    where T : class
{
    public MyGenericClass()
    {
        InitializeComponent();
    }
}

public class MyGenericClassBase<T, U>
    where U : class, new()
    where T : class, new()
{
    T _t;
    U _u;
    public MyGenericClassBase()
    {

    }
}

I want to did the class "MyGenericClass" in XAML but I can't !

I try it :

<MyGenericClassBase x:Class="MyGenericClass"  
         x:TypeArguments="class,class"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

       ...

How can i pass the argument type at my "MyGenericClass" and the inherit class "MyGenericClassBase "

Thanks a lot

Nico

Upvotes: 2

Views: 956

Answers (1)

alf
alf

Reputation: 18550

XAML 2006: You can't use generic types in xaml 2006. The easiest solution is to use MyClass directly. Check out this question for other workarounds: Can I specify a generic type in XAML (pre .NET 4 Framework)?

XAML 2009: Generic types are supported natively:

<MyGenericClass x:TypeArguments="x:Int32, x:String"> 
    ...
</MyGenericClass>

Upvotes: 3

Related Questions