ResourceDictionary 键的顺序是如何确定的?

发布于 2024-11-26 01:04:33 字数 737 浏览 7 评论 0原文

我有以下 ResourceDictionary (缩短):

<ResourceDictionary>
  <Fluent:RibbonContextualTabGroup Header="Dokument" x:Key="dokumentRibbonGroup" x:Name="dokumentRibbonGroup" />
  <Fluent:RibbonTabItem x:Key="dokumentRibbonTab" Header="Start" />
  <Fluent:RibbonTabItem x:Key="ueberpruefenRibbonTab" Header="Überprüfen" />
  <Fluent:RibbonTabItem x:Key="austauschRibbonTab" Header="Austausch" />
</ResourceDictionary>

当我访问字典的 Keys 属性时,键按以下顺序排列:

dokumentRibbonTab
austauschRibbonTab
ueberpruefenRibbonTab
dokumentRibbonGroup

我没有任何意义的顺序。它不是按字母顺序排列的,不是颠倒的,特别是不是原始的顺序。有人有提示吗?或者更好的是,关于如何指定 ResourceDictionary 中的项目顺序的建议?

I've got the following ResourceDictionary (shortened):

<ResourceDictionary>
  <Fluent:RibbonContextualTabGroup Header="Dokument" x:Key="dokumentRibbonGroup" x:Name="dokumentRibbonGroup" />
  <Fluent:RibbonTabItem x:Key="dokumentRibbonTab" Header="Start" />
  <Fluent:RibbonTabItem x:Key="ueberpruefenRibbonTab" Header="Überprüfen" />
  <Fluent:RibbonTabItem x:Key="austauschRibbonTab" Header="Austausch" />
</ResourceDictionary>

When I access the Keys property of the dictionary, the keys are in the following order:

dokumentRibbonTab
austauschRibbonTab
ueberpruefenRibbonTab
dokumentRibbonGroup

I can't make any sense of that order. It's not alphabetical, not revserse and in particular not the original order. Does anyone have a hint? Or even better, a suggestion on how to specify the order of items in a ResourceDictionary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2024-12-03 01:04:33

它很可能以某种方式基于哈希码。 (但不一定只是“按哈希码的升序排列”。)特别是,文档指出:

ResourceDictionary 类不是从 DictionaryBase 派生的。相反,ResourceDictionary 类实现 IDictionary,但内部依赖于 Hashtable。

鉴于它使用哈希表,顺序很可能取决于哈希。

通常,字典不是有序的 - 或者更确切地说,顺序是不应该依赖的实现细节。

鉴于我看不到任何指定顺序的文档,我认为您应该将其视为无序。如果您想按特定顺序显示密钥,您应该自己执行此操作。

It may well be based on hash code somehow. (Not necessarily just "in ascending order of hash code" though.) In particular, the docs state:

The ResourceDictionary class is not derived from DictionaryBase. Instead, the ResourceDictionary class implements IDictionary but relies on a Hashtable internally.

Given that it uses a hash table, it's likely that the order depends on the hash.

Typically dictionaries aren't ordered - or rather, the order is an implementation detail which shouldn't be relied on.

Given that I can't see any documentation specifying the ordering, I think you should treat it as unordered. If you want to present the keys in a particular order, you should do that yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文