WPF ListView的改变滚动速度 [英] WPF change ListView scroll speed

查看:1347
本文介绍了WPF ListView的改变滚动速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ListView 有定制的细胞(项目)。

I have a ListView with custom-made cells (items).

的ListView 重新presents两个人交换消息与我的应用程序之间的对话。每次添加一个消息,通话自动滚动到最后一个项目。

This ListView represents a conversation between two persons exchanging messages with my application. Each time a message is added, the conversation auto-scrolls to the last item.

我面临着一些奇怪的问题:

I am facing a few "strange" issues :

当用户写一个相当长的消息(比如,10号线),那么它就可以占据几乎整个屏幕(即分配给的ListView 空格),这是正常的,当然后来的滚动有点

When a user writes a rather long message (say, 10 lines), it can then take up almost the whole screen (meaning the space allocated to the ListView) which is normal of course but then the scrolling is somewhat broken.

首先,当列表自动滚动到这个消息,大的白色空间出现在项目下一路下跌到我的的ListView 的底部。见图片:

First, when the list auto-scrolls to this message, a big white space appears below the item all the way down to the bottom of my ListView. See picture :

和消息时都非常短(单行):

And when messages are very short (single line) :

其次,在所有的情况下,滚动速度是方法快。一个单一的谅解备忘录轮中风(作为滚动手指的感觉)将太快移动滚动条:多达4个的小消息滚动!这太过分了!

Second, and in all cases, the scroll speed is way to fast. A single mous-wheel "stroke" (the feeling in your finger as you scroll) will move the scroll bar too fast : up to 4 small messages are scrolled ! That's too much !

所以,问题是:如何控制滚动速度?如何慢下来?为什么会有这么大的空白?感谢您的帮助!

So question is : how to control the scroll speed ? How to slow it down ? Why is there this big white space ? Thanks for the help !

所要求@CurtisHx我的的ListView的XAML 情况如下:

Requested by @CurtisHx my ListView XAML is as follow :

http://pastebin.com/FFZGhi6w

我希望它有助于理解我的问题!

I hope it helps understanding my issue!

推荐答案

的一种方式是设置 ScrollViewer.CanContentScroll =FALSE的ListView 。 <一href=\"https://social.msdn.microsoft.com/Forums/vstudio/en-US/47bd6a75-7791-4c0f-93ae-931e9a6540e7/smooth-scrolling-on-listbox?forum=wpf\" rel=\"nofollow\">https://social.msdn.microsoft.com/Forums/vstudio/en-US/47bd6a75-7791-4c0f-93ae-931e9a6540e7/smooth-scrolling-on-listbox?forum=wpf

One way to be to set ScrollViewer.CanContentScroll="False" on the ListView. https://social.msdn.microsoft.com/Forums/vstudio/en-US/47bd6a75-7791-4c0f-93ae-931e9a6540e7/smooth-scrolling-on-listbox?forum=wpf

您将失去对的ListView 虚拟化,所以要在的ListView 元素的数量来合理地。这应该可以解决快速滚动速度。

You will loose virtualization on the ListView, so keep the number of elements in the ListView to something reasonable. That should fix the fast scroll speed.

文本对齐

文本被正确对齐。目前,父容器限制的TextBlocks的宽度的TextBlocks 将包裹文本之前填满所有的横向空间就可以了。因此,对于长的消息,在的TextBlock ,直至碰到父容器的限制将水平扩展。

The text is being aligned correctly. Currently, the parent container limits the width of the TextBlocks. TextBlocks will fill all of the horizontal space it can before wrapping the text. So for long messages, the TextBlock will expand horizontally until it hits the limits of the parent container.

为了得到交错文本,消息的宽度必须小于的ListView 的宽度。如果您加宽窗口,你会看到交错变成文字。下面是code的SNIPPIT,指出的TextBlock ,需要加以宽度有限的。

In order to get the staggered text, the width of the message needs to be less than width of the ListView. If you widen the window, you'll see the text become staggered. Below is a snippit of code, pointing out the TextBlock that needs to be width limited.

<ListView x:Name="ConversationList" ScrollViewer.IsDeferredScrollingEnabled="False" ScrollViewer.CanContentScroll="False" ScrollViewer.VerticalScrollBarVisibility="Auto"
            BorderBrush="Transparent" Grid.Row="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,10,10">
     <!-- Big Snip /!-->
     <ListView.ItemTemplate>
        <DataTemplate>
           <!-- Snip /!-->
           <Border Padding="0, 15, 0, 15">
              <Grid x:Name="ConversationBubble">
                 <Grid.RenderTransform>
                    <TranslateTransform />
                 </Grid.RenderTransform>
                 <Border Margin="70, 5, 70, 5" HorizontalAlignment="{Binding Alignment}" BorderBrush="#ECECEC" Visibility="Visible" Background="#F1F1F2"  Padding="10">
                    <StackPanel>


                            
                           
                              
                              
                              
                           
                           
                              
                           
                           
                        
                     
                  
               
            
         
      

这篇关于WPF ListView的改变滚动速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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