0

シンプルに書いているので、アイテムの表示WPF Applicationに使いたいと思いました。私のコードは次のとおりです。ListViewList

WPF.xaml

<ListView Grid.Column="0" Grid.Row="1" Margin="10,0,10,5" ItemsSource="{Binding MyCollection.Elements}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding ElementDescriptions}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

WPF.xaml.cs

public MyViewModel ViewModel
    {
        get { return DataContext; }
        set { DataContext = value; }
    }

MyViewModel.cs

public OwnedCollection Elements { get; set; }

OwnedCollection.cs

public List<ElementDescriptions> ElementDescriptions { get; set; }

簡単なメッセージを表示しても問題がないので、との間の通信は正しいViewと100%確信しています。ViewModel私は正しいバインディングをしていListViewますか?

4

1 に答える 1

0

いくつかのこと:

初め、

TextBlock Text="{Binding ElementDescriptions}"

ElementDescriptions はコレクションであるため、あまり意味がありません。リスト内のすべての ElementDescriptions をループしたい場合は、実際には ListView の ItemSource を ElementDescriptions にバインドしてから、ElementDescriptions クラスのテキスト プロパティにアクセスする必要があります。

<ListView Grid.Column="0" Grid.Row="1" Margin="10,0,10,5" ItemsSource="{Binding MyCollection.ElementsElementDescriptions }">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ElementDescriptions.SomeTextField}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

次に、INotifyPropertyChanged を使用して、ビューが更新することを認識していますか? 詳細はこちら: OnPropertyChanged with a List

于 2013-01-10T19:51:46.010 に答える