2

Dictionary<string,string>表示したいデータを含む がありますListView。はListView間違いなく適切な数のアイテムを「認識」しますが (2 番目の から適切な数のコロンが表示されるため) 、 もバインディングTextBlockも表示しません。KeyValue

Converterまたは何かが必要ですか?

代わりに を変更して使用する必要がありますObservableCollection<KeyValuePair<string,string>>か?

<ListView Grid.Row="1" IsItemClickEnabled="False" 
          SelectionMode="None" IsHitTestVisible="False"
          IsSwipeEnabled="False"
          ItemsSource="{Binding SymbolInfoText}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Key}"/>
                <TextBlock Text=": "/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

public Dictionary<string, string> SymbolInfoText
{
    get
    {
        if (selectedItem == null)
        {
            return new Dictionary<string, string> { { "Error", "No Item Selected" } };
        }
        return selectedItem.GenerateObjectProperties(CurrentLocation, LocalMapManager.Map.Heading);
    }
}
4

2 に答える 2

0

事後 (アプリケーションが起動され、バインディング リンクが確立された後) に項目を追加する場合は、Dictionary<string,string>実装されていないため、最適な選択ではありませんINotifyCollectionChanged。要素がディクショナリに追加された後に right を設定してみてくださいItemsSource。実際にアイテムがリストに表示されることがわかります。バインディングを更新するだけで済みます。

そうObservableCollection<T>です、コアコレクションに変更が発生したときに通知を送信するため、はるかに最適なソリューションになります。

于 2013-03-12T03:47:53.677 に答える