我很难找到一个列表来绑定到我的ListBox。下面是代码:
using System.Collections.ObjectModel;
using Rocky.Data;
namespace Rocky.UI.Wpf
{
using System.Windows;
internal partial class ShellWindow : Window
{
public ShellWindow()
{
InitializeComponent();
ViewModel = new ShellViewModel();
}
public static ReadOnlyCollection<AuthorInformation> AuthorList
{
get { return AuthorRepository.Authors; }
}
public ShellViewModel ViewModel
{
get { return DataContext as ShellViewModel; }
set { DataContext = value; }
}
}
}AuthorRepository.Authors只是从IList创建的一个ReadOnlyCollection。如果需要的话,我可以粘贴这些代码,但是我很确定错误不在这个类中。然后,这里是ListBox:
<ListBox
Name="AuthorListBox"
Grid.Row="1"
Margin="3"
VerticalAlignment="Stretch"
Background="Cornsilk"
ItemsSource="{Binding AuthorList}">
</ListBox>在编译或运行时,我不会遇到错误。但是,ListBox并没有被填满。不知道我做错了什么。我在这里看过很多其他帖子。到目前为止没有什么帮助。
发布于 2015-07-27 20:07:45
AuthorList属性应该在ShellViewModel类中。
https://stackoverflow.com/questions/31661239
复制相似问题