列表框滚动条拇指大小发生变化时,内容是可变的高度 [英] Listbox scrollbar thumb changes size when content is variable height

查看:130
本文介绍了列表框滚动条拇指大小发生变化时,内容是可变的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示多个对象,其中每个可以是可变高度的基础上,值的每个对象具有的数量的列表框。 见我以前是在这里回答问题。

I have a ListBox with many objects displayed, each of which can be a variable height, based on the number of values each object has. See my previous question that was answered here.

许多对象是5线高,而另一些则1.在列表框滚动条不会出现像现在这样,可能是由于虚拟化。当你翻阅,滚动条拇指将改变其大小的基础上,有多少项目实际上被装修成箱在那瞬间电流。这使得拇指有时很大,而在其他时间很少。

Many objects are 5-lines high, while others are 1. The scroll bar in the ListBox does not appear to like this, probably due to the virtualization. While you scroll through, the thumb on the scroll bar will change its size, based on how many items are actually fitting into the box at that current moment. This makes the thumb very big at times, and very small at other times.

由于此列表框也包含一个TabControl中,当你从一个选项卡切换到另一个,当您返回到它ListBox中往往会滚动到不同的部分。

Since this ListBox is also contained within a TabControl, when you switch from one tab to another, the ListBox will often scroll to a different section when you return to it.

任何想法如何解决这样的问题?

Any ideas how to resolve an issue like this?

其他信息:
禁用虚拟化不会修复滚动问题,尽管以较慢的初始显示的成本。然而,与内容调整大小列表框水平调整里面的时候会导致一些重滞(纵是罚款),这我假设是因为我的模板宽度变化,需要重新绘制的每个元素:

Additional Info: Disabling virtualization does fix the scrolling problem, although at the cost of a slower initial display. However, resizing the ListBox with the content inside causes some heavy lag when resizing horizontally (vertical is fine), which I'm assuming is due to my template's width changing and requiring a redraw on every element:

<DataTemplate DataType="{x:Type xmlset:Variable}">
    <Grid>
    	<Grid.ColumnDefinitions>
    		<ColumnDefinition Width="170"/>
    		<ColumnDefinition Width="*"/>
    	</Grid.ColumnDefinitions>
    	<Border BorderThickness="1,0,0,1" BorderBrush="Black">
    		<TextBlock Margin="2,2,0,2"  Text="{Binding Path=Identifier.Name, Mode=OneWay}"/>
    	</Border>
    	<ItemsControl IsTabStop="False" Grid.Column="1" ItemsSource="{Binding Path=Values, Mode=OneWay}">
    		<ItemsControl.ItemTemplate>
    			<DataTemplate>
    				<Grid>
    					<Grid.ColumnDefinitions>
    						<ColumnDefinition Width="120"/>
    						<ColumnDefinition Width="*"/>
    					</Grid.ColumnDefinitions>

    					<Border Grid.Column="0" BorderThickness="1,0,0,1" BorderBrush="Black">
    						<TextBlock Margin="2,2,0,2" Text="{Binding Path=Optimization, Mode=OneWay}"/>
    					</Border>
    					<Border Grid.Column="1" Width="Auto" BorderThickness="1,0,1,1" BorderBrush="Black">
    						<TextBox Margin="0,2,0,2" BorderThickness="0" Text="{Binding Path=Value}" TextChanged="TextBox_TextChanged"/>
    					</Border>
    				</Grid>
    			</DataTemplate>
    		</ItemsControl.ItemTemplate>
    	</ItemsControl>
    </Grid>
</DataTemplate>

这是周围绘制领域的边缘边界进行可视分组,其中val将延伸到内容大小。列表框也有Horizo​​ntalContentAlignmment =拉伸,以确保这看起来是正确的。

This is drawing borders around the edges of the fields to make a visual grouping, where val will stretch to the content size. The listbox also has HorizontalContentAlignmment = Stretch to ensure this looks correct.


-------------------
- var - opt - val -
-     -------------
-     - opt - val -
-     -------------
-     - opt - val -
-------------------

注:如果需要在不同的问题要问,告诉我,我会单独的问题

推荐答案

为什么不关闭在列表框本身的任何大小的限制,让它大小的内容,并将其包装成一个ScrollViewer中,对于设置一个适当大小?后者

Why not switch off any size restrictions on the ListBox itself, let it size to contents and wrap it into a ScrollViewer, setting a proper size for the latter?

标记应如下所示:

    <ScrollViewer Width="640px" Height="480px">
        <ListBox>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <!--Visualization of a list item-->
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>



我如果它是这样实现滚动过程中没有看到拇指大小changings。

I saw no thumb size changings during scrolling if it was implemented this way.

这篇关于列表框滚动条拇指大小发生变化时,内容是可变的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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