Mysterious `1 in XAML Datatype

I have no idea what to call it, so it may have already been reviewed many times.

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

In my xaml I use 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 that when building using local:TreeCategory assembly fails because the project complains that it does not know what the TreeCategory class TreeCategory . However, if I use:

 TreeCategory`1 

then the project builds great.

What is `1, why is it needed?

+6
source share
1 answer

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

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

So by deleting `1 , you are actually saying that the type is TreeCategory , not TreeCategory<T>

+7
source

Source: https://habr.com/ru/post/951777/


All Articles