0
votes

I am having trouble in declaring a DataTemplate for showing a list or grid of KeyValuePairs. I am setting the Content property of the below control in code behind when a ContentTemplate is declared as below.

        <esri:InfoWindow x:Name="MyInfoWindow" IsOpen="False"
                     Padding="2"
                     CornerRadius="0" 
                     Background="White"                         
                     ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}"
                     Map="{Binding ElementName=MyMap}" Content="Something">
            <esri:InfoWindow.ContentTemplate>
                <DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate">
                    <sdk:DataGrid>
                        <sdk:DataGrid.Template>
                            <ControlTemplate>
                                <TextBlock Text="{Binding}" Foreground="Black" FontSize="12" />
                            </ControlTemplate>
                        </sdk:DataGrid.Template>
                    </sdk:DataGrid>
                </DataTemplate>
            </esri:InfoWindow.ContentTemplate>
        </esri:InfoWindow>

The Textblock inside the ControlTemplate receives the object set in Content just fine, but as it should, it is showing type of the object received.

enter image description here

I had put in a DataGrid for the reason that it would show the collection (just key properties) in grid format if I put the binding as below, but if I write this, the output comes as empty.

<TextBlock Text="{Binding Path=Key}" Foreground="Black" FontSize="12" />

enter image description here

1

1 Answers

1
votes

As you can see the ObservableDictionary itself is being passed to that template, you can then pass that dictionary to an ItemsControl of some type.

Inside...

<sdk:DataGrid.Template>
    <ControlTemplate>
       <TextBlock Text="{Binding}" Foreground="Black" FontSize="12" />
    </ControlTemplate>
</sdk:DataGrid.Template>

Try something like...

<sdk:DataGrid.Template>
   <ControlTemplate>
      <ItemsControl ItemsSource="{Binding}">
         <ItemsControl.ItemTemplate>
            <DataTemplate>
               <TextBlock Text="{Binding Path=Key}" Foreground="Black" FontSize="12" />
            </DataTemplate>
         </TtemsControl.ItemTemplate>
      </ItemsControl>
    </ControlTemplate>
</sdk:DataGrid.Template>

See what that gives you.