2011-09-22 40 views
2

我有這些類泛型類型XAML 2009

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() 
    { 

    } 
} 

我想的確在XAML類「MyGenericClass」豆蔻問題,但我不能!

我試試吧:

<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" > 

     ... 

我怎麼能傳遞參數類型,在我的 「MyGenericClass」 和繼承類 「MyGenericClassBase」

非常感謝

尼科

+0

請使用評論系統收到寫評論的答案下。答案只是保留,答案。 –

回答

3

XAML 2006: 您不能在xaml 2006中使用泛型類型。最簡單的解決方案是直接使用MyClass。 看看這個問題的其他解決方法:Can I specify a generic type in XAML (pre .NET 4 Framework)?

XAML 2009年: 泛型類型的原生支持:

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

嗨阿方索,感謝您的快速回答,但這個話題並沒有幫助我!我無法在XAML中使用「MyClass」!我的問題是,如果我可以在XAML類中使用泛型(不是用於繼承類「MyGenericClassBase」,而是用於我的當前類「MyGenericClass」!謝謝 – Nicolas

+0

在做了一些挖掘之後,我發現泛型類型在XAML 2009中本地支持。編輯我的答案,告訴你如何做到這一點 – alf

+0

我知道這種情況,但它只適用於繼承類而不適用於我的主類「MyGenericClass」。代碼的參數x:TypeArguments僅適用於類「MyGenericClassBase」如果你有另一個想法?謝謝 – Nicolas