1

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}"  />

Platform: ArcGIS 10.1, WPF Runtime 10.1.1

Solution based on Antti Kajanus's answer below:

<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.

1

Instead of using DisplayMemberPath property try using ItemTemplate. You can access to Attributes collection with binding to {Binding Attributes[AttributeName]} in the ItemTemplate.

 <DataTemplate x:Key="MyDataTemplate">
     <TextBlock Text="{Binding Attributes[Title]}"/>
 </DataTemplate>

<ComboBox DataContext="{StaticResource MyViewModel}"
      ItemsSource="{Binding CollectionOfGraphics}"
      ItemTemplate="{StaticResource MyDataTemplate}"/>

I don't have now possibility to test if you can access to attribute from DisplayMemberPath but I remember that I had some issues with that on some point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.