Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysterious `1 in XAML Datatype

I have no idea what to call this, so it may have already been addressed numerous times.

I have a wrapper class for a collection:public class TreeCategory<T> : IEnumerable<T>

In my xaml I am using the class in the HierarchicalDataTemplate as follows:

<HierarchicalDataTemplate x:Key="m_CategoryTemplate"
     DataType="{x:Type local:TreeCategory`1}"   <--- WHAT IS THIS?!
     ItemsSource="{Binding CategoryCollection}" >
        <TextBox Text="{Binding CategoryName}" />
    </HierarchicalDataTemplate>

So my question is, when I build using local:TreeCategory the build fails, as the project complains it does not know what the class TreeCategory is. However if I use:

TreeCategory`1

then the project builds fine.

What is the `1, why is it necessary?

like image 247
mwjohnson Avatar asked Aug 15 '13 03:08

mwjohnson


1 Answers

http://msdn.microsoft.com/en-us/library/system.codedom.codetypereference.basetype.aspx

Generic types are formatted with the name of the type followed by a grave accent ("`") followed by a count of the generic type arguments.

So by removing the `1 you're actually saying the type is TreeCategoryand not TreeCategory<T>

like image 173
Ed W Avatar answered Nov 16 '22 04:11

Ed W