列表框默认情况下虚拟? [英] ListBox is virtual by default?

查看:165
本文介绍了列表框默认情况下虚拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF列表框与一些用户卡内。结果
当这些用户卡被创建(在理想情况下,在当前用户接收它是从网络朋友列表),它使一个用户的信息的网络请求。结果
当我在列表框滚动,等待几秒钟,然后向后滚动,用户卡有其默认状态。结果
经调试,我注意到他们被卸载并重新创建。

如何才能停止从虚拟化这样的项目列表框?


code:

 < ListBox的X:NAME =FRIEND_LIST背景={X:空}BorderBrush ={X:空}>
                < ListBox.ItemTemplate>
                    <数据类型的DataTemplate =数据:用户>
                        <东西:用户名UserCard ={绑定路径=用户名}的Horizo​​ntalAlignment =拉伸保证金=0,0,0,0/>
                    < / DataTemplate中>
                < /ListBox.ItemTemplate>
            < /列表框>


解决方案

设置<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.isvirtualizing.aspx\"><$c$c>VirtualizingStackPanel.IsVirtualizing要在的ListBox假或者设置一个正常的<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx\"><$c$c>StackPanel作为<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemspanel.aspx\"><$c$c>ListBox.ItemsPanel.

I have a WPF ListBox with some user cards inside.
When one of those user cards is created (in the ideal case, when the current user receives it's friend list from the network), it makes a network request for a user's information.
When I scroll in the ListBox , wait a few seconds, and scroll back, the user cards have their default state.
Upon debugging, I noticed they are unloaded and recreated.

How can I stop the ListBox from virtualizing the items like this?


Code:

            <ListBox x:Name="friend_list" Background="{x:Null}" BorderBrush="{x:Null}">
                <ListBox.ItemTemplate>
                    <DataTemplate DataType="data:User">
                        <stuff:UserCard UserID="{Binding Path=UserID}" HorizontalAlignment="Stretch" Margin="0,0,0,0" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

解决方案

Set VirtualizingStackPanel.IsVirtualizing to false on the ListBox or set a normal StackPanel as the ListBox.ItemsPanel.

这篇关于列表框默认情况下虚拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆