简体   繁体   English

WPF更改ListView滚动速度

[英]WPF change ListView scroll speed

I have a ListView with custom-made cells (items). 我有一个带有定制单元格(项目)的ListView

This ListView represents a conversation between two persons exchanging messages with my application. ListView表示两个人之间的对话,他们与我的应用程序交换消息。 Each time a message is added, the conversation auto-scrolls to the last item. 每次添加消息时,对话都会自动滚动到最后一项。

I am facing a few "strange" issues : 我面临一些“奇怪”的问题:

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 . 当用户编写一条较长的消息(例如10行)时,它几乎可以占据整个屏幕(这意味着分配给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 . 首先,当列表自动滚动到此消息时,项目下方一直出现一个大的空白,一直到我的ListView底部。 See picture : 看图片: 大消息和大空白的示例

And when messages are very short (single line) : 当消息很短时(单行): 短信示例

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 ! 单个拨轮“中风”(滚动时手指的感觉)会使滚动条移动得太快:最多滚动4条小消息! 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 ! 谢谢您的帮助 !

[UPDATE 1] [更新1]

Requested by @CurtisHx my ListView XAML is as follow : @CurtisHx请求,我的ListView XAML如下:

http://pastebin.com/FFZGhi6w http://pastebin.com/FFZGhi6w

I hope it helps understanding my issue! 我希望它有助于理解我的问题!

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

You will loose virtualization on the ListView , so keep the number of elements in the ListView to something reasonable. 您将在ListView上松开虚拟化,因此请使ListView的元素数量保持合理。 That should fix the fast scroll speed. 那应该解决快速滚动速度。

Text Alignment 文字对齐

The text is being aligned correctly. 文本正确对齐。 Currently, the parent container limits the width of the TextBlocks . 当前,父容器限制了TextBlocks的宽度。 TextBlocks will fill all of the horizontal space it can before wrapping the text. 在包装文本之前, TextBlocks将填充所有水平空间。 So for long messages, the TextBlock will expand horizontally until it hits the limits of the parent container. 因此,对于长消息, TextBlock将水平扩展,直到达到父容器的极限。

In order to get the staggered text, the width of the message needs to be less than width of the ListView . 为了获取交错的文本,消息的宽度需要小于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. 下面是一段代码,指出需要限制宽度的TextBlock

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM