gpt4 book ai didi

c# - XAML 数据类型中的神秘 `1

转载 作者:太空狗 更新时间:2023-10-29 21:28:08 24 4
gpt4 key购买 nike

我不知道该怎么调用它,所以它可能已经被解决过很多次了。

我有一个集合的包装类:public class TreeCategory<T> : IEnumerable<T>

在我的 xaml我正在使用 HierarchicalDataTemplate 中的类如下:

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

所以我的问题是,当我使用 local:TreeCategory 构建时构建失败,因为项目提示它不知道类 TreeCategory 是什么是。但是,如果我使用:

TreeCategory`1

然后项目构建正常。

什么是`1,为什么有必要?

最佳答案

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.

所以通过删除 `1你实际上是说类型是 TreeCategory而不是 TreeCategory<T>

关于c# - XAML 数据类型中的神秘 `1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18245712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com