[英]Binding with an appropriate UIElement for ObservableDictionary Silverlight
我在聲明用於顯示KeyValuePairs列表或網格的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" />
如您所見, ObservableDictionary本身已傳遞給該模板,然后可以將該字典傳遞給某種類型的ItemsControl 。
內...
<sdk:DataGrid.Template>
<ControlTemplate>
<TextBlock Text="{Binding}" Foreground="Black" FontSize="12" />
</ControlTemplate>
</sdk:DataGrid.Template>
嘗試類似...
<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>
看看會給你帶來什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.