开发者

If i added a lot of controls in StackPanel, the UI Virtualization is applied?

I have a some question about UI Virtualizing in StackPanel.

<ScrollViewer>
    <StackPanel Orientation="Vertical">
        <!--item1.-->
        <StackPanel Orientation="Horizontal" Margin="5">
            <Button/> 
            <TextBlock Text="oh hi."/>
        </StackPanel>        

        <!--item2.-->
        <StackPanel Orientation="Horizontal" Margin="5">
            <Button/> 
            <TextBlock Text="oh hi."/>
        </StackPanel>        

        <!--item3.-->
        <StackPanel Orientation="Horizontal" Margin="5">
            <Button/> 
            <TextBlock Text="oh hi."/>
        </StackPanel>        

        <!--item4.-->
        <StackPanel Orientation="Horizontal" Margin="5">
            <Button/> 
            <TextBlock Text="oh hi."/>
        </StackPanel>        

        ...


        <!--item9999.-->
        <StackPanel Orientation="开发者_JAVA技巧Horizontal" Margin="5">
            <Button/> 
            <TextBlock Text="oh hi."/>
        </StackPanel>        

    </StackPanel>
</ScrollViewer>

I heared about WPF UI Virtualization.

and then, If I add a lot of controls in StackPanel, A UI Virtualization works automatic at this StackPanel?

I know StackPanel.VirtualizingStackPanel.IsVirtualizing has setted to True by default.


There's nothing "virtual" about your example here, though. you've explicitly created 9999 items inside your stack panel.

Virtualization is when some other itemscontrol (like a list, tree, grid) has a virtualizing panel inside of it, and the items control is generating/removing/reusing items as necessary to make it appear that the stack panel has 9999 items in it, when it really has only a few.

the simplest comparison to your above would be a ListBox control, with an ItemsSource of a list of 9999 items in it, and a DataTemplate:

<ListBox ItemsSource="{Binding Path=TheListOf9999Items}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Margin="5">  
                <Button/>   
                <TextBlock Text="oh hi."/>  
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

the listbox internally would have a virtualizing stack panel (its ItemsPanel) which would then generate items as necessary as you scroll up and down.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜