ItemsControl虚拟化

时间:2018-08-01 08:39:57

标签: wpf wpf-controls

我正在使用ui,其中项目控件位于单独的用户控件中。

主视图代码为:

<DockPanel LastChildFill="True">
                <Border Background="{DynamicResource wcLightPanelBackgroundBrush}"
                        DockPanel.Dock="Top">
                    <StackPanel>
                        <TextBlock Text="Preview Data"
                                   Style="{DynamicResource LargeLabelStyle}" />
                        <Button Content="Populate"
                                Width="auto"
                                HorizontalAlignment="Left"
                                Command="{Binding PopulateImportRowCommand}"
                                Style="{DynamicResource FlatButtonDarkStyle}" />
                    </StackPanel>
                </Border>
                <loaderView:LoaderViewPreviewImportRowsView VerticalAlignment="Top"  />
            </DockPanel>

如果我未为项目控件指定高度,则项目控件虚拟化将无法​​工作。

我想绑定dockpanel的最后一个子项的高度,但是高度始终为0,因此它不会显示在ui中。

  <ItemsControl ItemsSource="{Binding ImportRows}"
                      VerticalAlignment="Top"
                      VirtualizingStackPanel.IsVirtualizing="True"
                      VirtualizingStackPanel.VirtualizationMode="Recycling">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ItemsControl ItemsSource="{Binding Columns}"
                                  VerticalAlignment="Top"
                                  VirtualizingStackPanel.IsVirtualizing="True"
                                  VirtualizingStackPanel.VirtualizationMode="Recycling">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="DarkGray"
                                        BorderThickness="0,0,1,0">
                                    <TextBlock Text="{Binding Data}"
                                               FontFamily="Courier New"
                                               Foreground="{DynamicResource wcBodyFontBrush}"
                                               FontSize="{DynamicResource LargeFontSize}" />
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.Template>
                            <ControlTemplate>
                                <Border>
                                    <ScrollViewer VerticalScrollBarVisibility="Hidden"
                                                  CanContentScroll="True">
                                        <ItemsPresenter />
                                    </ScrollViewer>
                                </Border>
                            </ControlTemplate>
                        </ItemsControl.Template>
                    </ItemsControl>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.Template>
                <ControlTemplate>
                    <Border>
                        <ScrollViewer VerticalScrollBarVisibility="Visible"
                                      CanContentScroll="True">
                            <ItemsPresenter />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ItemsControl.Template>
        </ItemsControl>

所以我的问题是,有没有办法使虚拟化在不指定高度的情况下工作?

0 个答案:

没有答案