0

WPFコンボボックスがあります

  <ComboBox x:Name="tCountry" HorizontalAlignment="Left" Margin="96,151,0,0" VerticalAlignment="Top" Width="146" TabIndex="6"/>

そして私がユニコードから抽出したいくつかのxmlデータ(CLDR)

<?xml version="1.0" encoding="UTF-8" ?>
<country>
    <territory type="AC">Ascension Island</territory>
    <territory type="AD">Andorra</territory>
    <territory type="AE">United Arab Emirates</territory>
    <territory type="AF">Afghanistan</territory>
    <territory type="AG">Antigua and Barbuda</territory>
    <territory type="AI">Anguilla</territory>
    <territory type="AL">Albania</territory>
    ....
</country>

コンボボックスにこれらの国が表示され、vb.netでデータを送信するときに2文字のISOコードを抽出できるようにするには、どうすればよいですか。

4

1 に答える 1

0

を使用しXmlDataProviderて、XMLファイルからフィールドを取得できます。

<XmlDataProvider x:Key="xml" Source="data.xml" />

XPath次に、SelectedValuePath属性を使用してバインドします。

<ComboBox ItemsSource="{Binding Source={StaticResource xml},XPath=/country/territory}" 
     SelectedValuePath="{Binding XPath=@type}" />

次に、を使用SelectedValueして略語を取得します(またはそのバインディングを使用します)。

private void combo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    MessageBox.Show((string)(sender as ComboBox).SelectedValue);
}
于 2012-10-20T06:57:33.723 に答える