3

I'm trying to bind a combobox to a ObservableCollection.When the form is displayed the combobox is empty.The same code with ObservableCollection of type string works perfectly. I've got a feeling that my XPath is wrong. Any suggestions are welcome:

XAML:

<ComboBox ItemsSource="{Binding ItemParameters, XPath=InnerXml/name,Mode=TwoWay}" SelectedIndex="0" Margin="2" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" Grid.Row="1" Grid.Column="1" Height="24"  />

ObservableCollection XmlNode :

public ObservableCollection<XmlNode> _itemParameters = new ObservableCollection<XmlNode>();
public ObservableCollection<XmlNode> ItemParameters
{
    get { return _itemParameters; }
    set { _itemParameters = value; }
}

The combobox should display the name attribute of each XmlNode in the collection: enter image description here

Update:

I've tried using DisplayMemberPath in two different ways, but the combobox still contains no data:

DisplayMemberPath="{Binding XPath=name}" ItemsSource="{Binding ItemParameters}"
DisplayMemberPath="{Binding XPath=InnerXml/name}" ItemsSource="{Binding ItemParameters}"

Solution:

This did the trick, hope it helps someone else as well:

<ComboBox DisplayMemberPath="@name" ItemsSource="{Binding ItemParameters}"
4

1 に答える 1

3

まず第一に、競合するプロパティを設定しているPathXPath同時に、アイテムItemsSourceに表示したいものとは何の関係もない をバインドします。そのためにまたはを使用します。は にバインドする必要があります。DisplayMemberPathItemTemplateItemsSourceItemParameters

于 2012-06-27T10:08:27.407 に答える