我的XAML中有一个ListView定义为
<vm:JobListView x:Name="JobEditor" ItemsSource="{Binding Path=JobListViewSource}">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Width="10" HeaderContainerStyle="{DynamicResource FirstColumnGridViewColumnHeader}" CellTemplate="{StaticResource EmptyColumnTemplate}" />
<vm:SortListViewColumn Header="Description" Width="100" SortProperty="Description" SortStyle="JobDataGridViewColumnHeader" CellTemplate="{StaticResource DescriptionColumnTemplate}" />
<vm:SortListViewColumn Header="Staff" Width="100" SortProperty="Staff.FirstName" SortStyle="JobDataGridViewColumnHeader" CellTemplate="{StaticResource StaffColumnTemplate}" />
<vm:SortListViewColumn Header="Client" Width="50" SortProperty="Client.Name" SortStyle="JobDataGridViewColumnHeader" CellTemplate="{StaticResource ClientColumnTemplate}" />
<vm:SortListViewColumn Header="Samples" Width="100" SortProperty="Samples" SortStyle="JobDataGridViewColumnHeader" CellTemplate="{StaticResource SamplesNoColumnTemplate}" />
<vm:SortListViewColumn Header="Entry Date" Width="100" SortProperty="EntryDate" SortStyle="JobDataGridViewColumnHeader" CellTemplate="{StaticResource EntryDateColumnTemplate}" />
<GridViewColumn Width="10" CellTemplate="{StaticResource EmptyColumnTemplate}" />
</GridView>
</ListView.View>
</vm:JobListView>
vm:JobListView是一个继承自ListView
的类CellTemplates的定义如下: -
<!-- description column -->
<DataTemplate x:Key="DescriptionColumnTemplate">
<TextBox Style="{StaticResource ReadOnlyTextBlockStyle}" Text="{Binding Path=Description}" />
</DataTemplate>
ItemsSource绑定到我的VM上的属性,如下所示: -
public ICollectionView JobListViewSource
{
get { return Get(() => JobListViewSource); }
set { Set(() => JobListViewSource, value); }
}
我设置了这样的属性: -
CollectionViewSource source = new CollectionViewSource();
source.Source = this.Jobs;
this.JobListViewSource = source.View;
其中Jobs是Job对象的ObservableCollection
我在网格中显示的只是Job对象的命名空间而不是每列中的各个属性
我做错了什么?
答案 0 :(得分:0)
尝试使用
this.JobListViewSource.SourceCollection = this.Jobs而不是
CollectionViewSource source = new CollectionViewSource();
source.Source = this.Jobs;
this.JobListViewSource = source.View;