Select to view content in your preferred language

Databinding ComboBox to GraphicsCollection

928
2
Jump to solution
08-08-2013 09:41 AM
KeithGemeinhart
Regular Contributor
Greetings,

I'd like to bind a GraphicsCollection (which is a property in a view model) to a combo box in a XAML window. The problem is I can't figure out how to display attribute values in the combo box. I can get it to display the Geometry property like this:
<ComboBox DataContext="{StaticResource MyViewModel}"                 DisplayMemberPath="Geometry"                 ItemsSource="{Binding CollectionOfGraphics}"  />


But I want to be able to do something like this that will display the OBJECTID or some other attribute:
<ComboBox DataContext="{StaticResource MyViewModel}"                 DisplayMemberPath="Attributes[&quot;OBJECTID&quot;]"                 ItemsSource="{Binding CollectionOfGraphics}"  />


I also tried this approach - unsuccessfully:

<ComboBox DataContext="{StaticResource MyViewModel}"                 DisplayMemberPath="Attributes[0]"                 ItemsSource="{Binding CollectionOfGraphics}"  />
0 Kudos
1 Solution

Accepted Solutions
2 Replies
AnttiKajanus1
Deactivated User
0 Kudos
KeithGemeinhart
Regular Contributor
Here is the solution based on Antti Kajanus's answer on stackexchange:

<ComboBox DataContext="{StaticResource MyViewModel}"
                ItemsSource="{Binding CollectionOfGraphics}" >
     <ComboBox.ItemTemplate>
          <DataTemplate>
              <TextBlock Text="{Binding Attributes[OBJECTID]}"/>
          </DataTemplate>
     </ComboBox.ItemTemplate>
</ComboBox>


Note that the attributite name (OBJECTID) did not have to be quoted.
0 Kudos