这是我的 MainWindow.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MultipleProjectViewModel();
}
我的视图模型:
public class MultipleProjectViewModel : ViewModelBase
{
private ObservableCollection<Project> _projectCollection;
public MultipleProjectViewModel()
{
ProjectCollection = new ObservableCollection<Project>();
ProjectCollection.Add(new Project(){Name = "baba",Description = "lala"});
}
public ObservableCollection<Project> ProjectCollection
{
get { return this._projectCollection; }
set
{
if(_projectCollection != value)
{
_projectCollection = value;
RaisePropertyChanged(()=> ProjectCollection);
}
}
}
}
我的模型:
public class Project
{
public string Name { get; set; } // Project Name
public string Description { get; set; } // Project Description
}
我的观点:
<ListView ItemsSource="ProjectCollection">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding Path=Description}"/>
</GridView>
</ListView.View>
</ListView>
那么为什么绑定不起作用?当我编译它时,我只看到一个空白的 GridView。