我有一个WPF应用程序与DataGrid和ListView共享相同的ObservableCollection ItemsSource。当DataGrid的CanUserAddRows属性为True时,它会导致ListView显示DataGrid用来添加新行的额外项目。具有相同itemssource的Datagrid和Listview
如何从DataGrid中获取额外的行以便不在ListView中显示?
我尝试使用上ListView控件的DataTemplate中的触发器和检查,如果项目编号为空或0
`<ListView.ItemTemplate>
<DataTemplate>
<Label Margin="-2,0,0,0" Name="CategoryLabel" >
<TextBlock TextWrapping="Wrap" Text="{Binding categoryName}" Height="46"></TextBlock>
</Label>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding categoryId}" Value="0" > <!-- also tried Value="" -->
<Setter TargetName="CategoryLabel" Property="Visibility" Value="Hidden" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListView.ItemTemplate>`
只是一些指针:创建的ListCollectionView(它的来源是你的ObservableCollection)与'ListCollectionView.Filter'回调,并将其分配到'ListBox.ItemsSource'财产。在过滤器回调,然后检查由DataGrid添加的占位符项... – elgonzo
我第二@elgonzo似乎是正确的方法。 –