【发布时间】:2014-12-16 19:14:19
【问题描述】:
我在声明用于显示 KeyValuePair 列表或网格的 DataTemplate 时遇到问题。当 ContentTemplate 声明如下时,我正在后面的代码中设置以下控件的 Content 属性。
<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>
ControlTemplate 中的 Textblock 可以很好地接收 Content 中设置的对象,但它应该显示接收到的对象的类型。
我放入 DataGrid 的原因是,如果我将绑定如下所示,它将以网格格式显示集合(只是关键属性),但如果我写这个,输出为空。
<TextBlock Text="{Binding Path=Key}" Foreground="Black" FontSize="12" />
【问题讨论】:
标签: c# wpf silverlight data-binding