Was ist die gute Möglichkeit, eine Liste von Auswahlmöglichkeiten für ein Kombinationsfeld oder ein Listenfeld in XAML zu vertreten?

StackOverflow https://stackoverflow.com/questions/1401167

Frage

Alles ist kompakter (oder auf andere Weise besser) als

    <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>

War es hilfreich?

Lösung

Ohne Code, ist die consice Sie können AFAIK.

Andere Tipps

<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>

Ein Vorteil dieses Ansatzes ist, dass Sie die Einzelteile vollständig getrennt von den XAML halten können, wenn Sie brauchen, um -. Sie sie in einem externen XML-Dokument zu speichern und die XmlDataProvider zur Laufzeit laden, wenn Sie benötigen

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top