XAML 将ComboBox ItemsSource绑定到ResourceDictionary的所有键

piwo6bdm  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(107)

我有一个包含多个x:Key元素(图标列表)的ResourceDictionary。我希望将一个ComboBox ItemsSource绑定到ResourceDictionary中的键列表。

<UserControl.Resources>
    <ResourceDictionary x:Name="Icons" Source="..."/>
</UserControl.Resources>

<Grid>
    <ComboBox ItemSource = {Binding ?}> //How to Bind here to Icons keys?
</Grid>

我考虑将字典加载到后面的代码中,然后使用

combobox1.ItemsSource = // Load dictionary keys here

但是我想知道我是否可以直接使用XAML?

juzqafwq

juzqafwq1#

抱歉我的问题不够清楚,最后解决的办法很简单,绑定应该是这样的I-

<CombBox ItemsSource="{Binding ElementName=Icons, Path=Keys}"/>

相关问题