在XAML中表示组合框或列表框的选项列表的好方法是什么?
题
任何事情都比
更紧凑(或更好) <x:Array x:Key="titles" Type="System:String">
<System:String>Mr.</System:String>
<System:String>Mrs.</System:String>
<System:String>Ms.</System:String>
</x:Array>
解决方案
如果没有代码,那么你可以使用AFAIK。
其他提示
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<XmlDataProvider x:Key="Lookups">
<x:XData>
<ComboBoxItems xmlns="">
<Salutations>
<Item>Mr.</Item>
<Item>Mrs.</Item>
<Item>Ms.</Item>
</Salutations>
<States>
<Item>AL</Item>
<Item>AK</Item>
<Item>CA</Item>
<Item>CT</Item>
</States>
<Wizards>
<Item>Gandalf</Item>
<Item>Radagast</Item>
<Item>Pallando</Item>
<Item>Saruman</Item>
</Wizards>
</ComboBoxItems>
</x:XData>
</XmlDataProvider>
</Page.Resources>
<StackPanel>
<ComboBox ItemsSource="{Binding Source={StaticResource Lookups}, XPath=ComboBoxItems/Salutations/*}"/>
<ComboBox ItemsSource="{Binding Source={StaticResource Lookups}, XPath=ComboBoxItems/States/*}"/>
<ComboBox ItemsSource="{Binding Source={StaticResource Lookups}, XPath=ComboBoxItems/Wizards/*}"/>
</StackPanel>
</Page>
这种方法的一个优点是,如果需要,您可以完全独立于XAML维护项目 - 您可以将它们存储在外部XML文档中,并在运行时加载 XmlDataProvider
需要。
不隶属于 StackOverflow