在Windows 8应用程序中通过手指触摸滚动ListBox的问题

时间:2013-01-09 14:24:42

标签: c# windows-8 visual-studio-2012 microsoft-metro winrt-xaml

我开发了一个Windows 8应用程序,其中我在ListBox控件中提供了一个newsarea。对于新闻项目,我使用模板。新闻项目有不同的大小。项目的大小将在LayoutUpdate事件之后设置。如果我用手指Tuuch滚动列表,则会出现闪烁效果。这是因为我随后调整的项目数量。当我使用恒定大小时,我没有闪烁效果的问题。当我用鼠标滚动列表时没有问题。是否有人喜欢这种闪烁效果?每个人都有类似的问题并对我有所帮助吗?

我的模板:

<UserControl
    x:Class="components.NewsItemRenderer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="150"
    d:DesignWidth="560" >

    <Canvas x:Name="rootCanvas"
            Width="560"
            Height="150">

        <TextBlock x:Name="lbl_title"
                   Width="480"
                   Canvas.Left="15"
                   Canvas.Top="35"
                   MaxHeight="50"
                   SizeChanged="lbl_description_SizeChanged"
                   LayoutUpdated="lbl_title_LayoutUpdated"
                   Style="{StaticResource LabelTitle}"
                   Text="{Binding Path=message.title}"/>

        <TextBlock x:Name="lbl_description"
                   Canvas.Left="15"
                   Canvas.Top="55"
                   Width="480"
                   SizeChanged="lbl_description_SizeChanged" 
                   Style="{StaticResource LabelDescription}"
                   Text="{Binding Path=message.description}"/>

    </Canvas>
</UserControl>  

private void lbl_description_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            lbl_description.SetValue(Canvas.TopProperty, lbl_title.ActualHeight + 45);
            double _height = lbl_subject.ActualHeight + lbl_title.ActualHeight + lbl_description.ActualHeight + 40;
            this.Height = _height;
            rootCanvas.Height = _height;
        }

我的控制:

<ListBox x:Name="viewBox"
     Visibility="Visible"
     Background="{x:Null}"
     Foreground="{x:Null}"
     Width="580"
     Height="580"
     BorderThickness="0"
     ItemsSource="{Binding Source={StaticResource newsMessages}}"
     ItemTemplate="{StaticResource newsTemplate}"
     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
     ItemContainerStyle="{StaticResource NoSelectListBoxItemStyle}" />

1 个答案:

答案 0 :(得分:0)

是。

最简单的方法是在XAML中使用IncrementalUpdateBehavior。

  

参考:http://marcominerva.wordpress.com/2014/01/15/using-incrementalupdatebehavior-to-incrementally-show-data-in-listviewbase-controls/

     

参考:http://blogs.msdn.com/b/hanxia/archive/2013/11/04/incremental-update-item-data-for-listviewbased-controls-in-windows-8-1.aspx

这基本上允许您识别DataTemplate中应该在滚动时首先显示的部分。像这样切割你的UI可以让XAML绘画更快,减少闪烁。

话虽如此,我也想说这个。有时由于我们展示的数据量,我们需要对数据模板的复杂性做出妥协。那可能是你的情况。

祝你好运!