ResourceDictionary 键的顺序是如何确定的?
我有以下 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它很可能以某种方式基于哈希码。 (但不一定只是“按哈希码的升序排列”。)特别是,文档指出:
鉴于它使用哈希表,顺序很可能取决于哈希。
通常,字典不是有序的 - 或者更确切地说,顺序是不应该依赖的实现细节。
鉴于我看不到任何指定顺序的文档,我认为您应该将其视为无序。如果您想按特定顺序显示密钥,您应该自己执行此操作。
It may well be based on hash code somehow. (Not necessarily just "in ascending order of hash code" though.) In particular, the docs state:
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.