WPF / C # Combobox DataBinding

To get started, I would like to apologize for my English, which is far from perfect (its not my native language ...).

I have a problem with data binding in my XAML code. I have a combox that should display all the graphic nodes that I drop onto a custom canvas. My graphic nodes are listed graphCanvas.uinodes, and each node has name. And this is what I want to show in my combo box.

So, I tried something like this:

<ComboBox ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes/name}"
    Height="23" HorizontalAlignment="Left" Name="comboBox1"
    VerticalAlignment="Top" Width="71" Foreground="Black"  />

But even after drawing the nodes on my canvas, my combox is empty ...

Any clue?

Thank.

+3
source share
2 answers

ElementName WPF . , Canvas uinodes, , Path -, , .

"" , , , . .

, . , :

<ComboBox ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes}" 
          DisplayMemberPath="name"/>

<ComboBox ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes}">
   <ComboBox.ItemTemplate>
      <TextBlock Text="{Binding name}"/>
   </ComboBox.ItemTemplate>
</ComboBox>
+1

( , Path) . , uinodes - , , `name ', . :

ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes}" DisplayMemberPath="name"

, .

0

All Articles