私はそのように定義されたWPFコンボボックスを持っています:
<ComboBox Grid.Column="1" x:Name="cUrls" SelectedIndex="1" ItemsSource=" {Binding XPath=//data/endpoints/endpoint}" Margin="5" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=@name}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
ウィンドウは、次のように XmlDocument にバインドされます。
<?xml version="1.0" encoding="utf-8" ?>
<data>
<endpoints>
<endpoint name="test">test url</endpoint>
<endpoint default="true" name="production">production url</endpoint>
</endpoints>
<requests>
<request >
...
</request>
<request >
...
</request>
</requests>
</data>
バインディングは正常に機能し、コンボ ボックスには「test」と「production」という項目が表示され、SelectedValue プロパティから正しい URL を取得できます。
SelectedIndex
ComboBox のプロパティを、属性<endpoint>
を持つノードのインデックスに設定できるようにしたいと考えていdefault=true
ます。
SelectedIndex="{Binding XPath=}"
ComboBoxでできますか?もしそうなら、その表現はどのように見えるでしょうか?そうでない場合は、どうすればよいですか?
ありがとう!