C#WPF在列表视图项上显示Listview控件

时间:2016-10-07 10:57:31

标签: c# .net wpf xaml listview

好的,所以我一直在寻找类似于树视图的WPF列表视图。我有一个数据模型,它有一个observeableCollection项目的子项。我已经看了几个选项,使用了一些树视图,这些选项已经在stackoverflow或CodeProject上显示,但它们要么不可绑定,要么太慢而无法使用。

该列表将在一天中不断更新,在一天结束时可能有超过50k-100k的项目。正常的listview控件似乎能够处理这些更新,并且在需要度假胜地时仍然无需完全冻结。

现在,我的数据对象实际上应该只有一层子节点。所以我想要尝试的是在列表视图项目上显示切换按钮(如果项目有子项),但是当单击切换按钮时,我想在当前listviewitem中显示该项目的子项的另一个列表视图。我一直在寻找超过一周的时间来试图弄清楚如何做到这一点。任何人都可以带领我朝着正确的方向前进吗?我想我需要一个Itemview的listview,但我不确定如何让子listview显示在父的listviewitem中。

提前致谢

更新: 这是我目前正在尝试使用的XAML示例,但它似乎没有正常工作。我想要列,但是当我单击切换按钮时,我希望显示子列表视图。目前我看到的只是列,我无法显示子列表视图。

<ListView ItemsSource="{Binding MyCollection, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" x:Name="lsvMyList">
     <ListView.ItemTemplate>
          <DataTemplate>
               <StackPanel Orientation="Vertical">
                    <ListView ItemsSource="{Binding Children}">
                         <ListView.View>
                              <GridView>
                                   <GridViewColumn Header="Column2"
                                                   DisplayMemberBinding="{Binding Column2}"
                                                   Width="100"/>
                                     <GridViewColumn Header="Column3"
                                                     DisplayMemberBinding="{Binding Column3}"
                                                     Width="100"/>
                                     <GridViewColumn Header="Column5"
                                                     DisplayMemberBinding="{Binding Column5}"
                                                     Width="100"/>
                                     <GridViewColumn Header="Column8"
                                                     DisplayMemberBinding="{Binding Column8}"/>
                                </GridView>
                           </ListView.View>
                      </ListView>
                 </StackPanel>
            </DataTemplate>
       </ListView.ItemTemplate>
       <ListView.View>
            <GridView>
                 <GridViewColumn Width="68" Header="IsExpanded">
                      <GridViewColumn.CellTemplate>
                           <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                     <ToggleButton Visibility="{Binding ChildCount, Converter={StaticResource Toggle}}"
                                                   x:Name="tbnItemExpander"
                                                   Content="+"
                                                   Height="15"
                                                   Width="15"
                                                   BorderThickness="0"
                                                   Background="Transparent"
                                                   IsChecked="{Binding IsExpanded, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"   
                                               HorizontalContentAlignment="Center"
                                                 VerticalContentAlignment="Center"
                                                   Click="Toggle_Click"/>

                                          <TextBlock VerticalAlignment="Center"
                                                     Text="{Binding ChildCount, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource RejectCount2}}"
                                                     Margin="2,0,2,0"/>
                                </StackPanel>
                            </DataTemplate>
                      </GridViewColumn.CellTemplate>
                 </GridViewColumn>
                 <GridViewColumn Header="Column2"
                                 DisplayMemberBinding="{Binding Column2, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"
                                Width="63"/>
                 <GridViewColumn Header="Column3"
                                 DisplayMemberBinding="{Binding Column2, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"
                                 Width="28"/>
                 <GridViewColumn Header="Column4"
                                 DisplayMemberBinding="{Binding Column2, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"
                                 Width="68"/>
                 <GridViewColumn Header=""
                                 Width="110">
                      <GridViewColumn.CellTemplate>
                           <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                     <Button Click="Button_Click"
                                             Margin="2" Padding="2"
                                             IsEnabled="{Binding Column5, Converter={StaticResource IsNull}}"
                                             Content="{Binding Converter={StaticResource btnContent}}"
                                             Tag="{Binding NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"/>
                                 </StackPanel>
                            </DataTemplate>
                       </GridViewColumn.CellTemplate>
                  </GridViewColumn>
             </GridView>
        </ListView.View>
   </ListView>

0 个答案:

没有答案