0
我在写简单的WPF Application
,我想用ListView
来显示List
的项目。我的代码是:ListView数据绑定
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; }
我100%肯定,View
和ViewModel
之间的通信是正确的,因为显示简单的消息并没有让我烦恼。我在做ListView
的正确绑定吗?
此行'的ItemsSource = “{结合MyCollection.Elements}'什么,当你将其更改为'发生的ItemsSource =”{结合MyCollection的}'也想知道如果OwnedCollection应改用的ObservableCollection .. – MethodMan
什么都没有 - 名单仍然是空的。依然没有。 – Fka
我已经将List更改为ObservableCollection –
Fka