[英]Binding with an appropriate UIElement for ObservableDictionary Silverlight
I am having trouble in declaring a DataTemplate for showing a list or grid of KeyValuePairs. 我在声明用于显示KeyValuePairs列表或网格的DataTemplate时遇到麻烦。 I am setting the Content property of the below control in code behind when a ContentTemplate is declared as below. 当按如下所示声明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>
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. ControlTemplate内的Textblock可以很好地接收Content中设置的对象,但是,它应该显示接收到的对象的类型。
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. 我放入DataGrid的原因是,如果我按如下所示进行绑定,它将以网格格式显示集合(只是关键属性),但是如果我编写此内容,则输出为空。
<TextBlock Text="{Binding Path=Key}" Foreground="Black" FontSize="12" />
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. 如您所见, ObservableDictionary本身已传递给该模板,然后可以将该字典传递给某种类型的ItemsControl 。
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. 看看会给你带来什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.