none
求助:使用GridView遇到的一个内存泄漏的问题 RRS feed

  • 问题

  • 我想实现这个功能:当用户操作滚动条时,Gridview控件的当前选择项始终保持为出现在屏幕中的那一项。

    //Scrollviewer的ViewChanged="GridView5_SV_ViewChanged_1",处理如下:

    void ReadPage::GridView5_SV_ViewChanged_1(Platform::Object^ sender, Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs^ e) { int nVerticalOffset = GridView5_SV->VerticalOffset; int nHeight = GridView5_SV->ExtentHeight; int nPageHeight = nHeight/m_nPageCount; int nIndex = nVerticalOffset/nPageHeight; if (GridView5->SelectedIndex!=nIndex) { GridView5->SelectedIndex = nIndex;//这一句造成内存增加并会产生泄漏 } }

    //Gridview的数据源是一个分组的数据集合

    <CollectionViewSource x:Name="cvs2" Source="{Binding Groups}" IsSourceGrouped="True" ItemsPath="Items" d:Source="{Binding ItemGroups, Source={d:DesignInstance Type=data:DataGroup, IsDesignTimeCreatable=True}}"/>

    //控件信息

    <ScrollViewer x:Name="GridView5_SV" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Visibility="Visible" ViewChanged="GridView5_SV_ViewChanged_1" PointerWheelChanged="GridView5_SV_PointerWheelChanged_1"> <GridView x:Name="GridView5" VerticalAlignment="Center" HorizontalAlignment="Center" SelectionMode="Single" PointerWheelChanged="GridView5_PointerWheelChanged_1" Visibility="Visible" IsSynchronizedWithCurrentItem="{x:Null}" ItemsSource="{Binding Source={StaticResource cvs2}}" ItemTemplate="{StaticResource DataTemplate1}"> </GridView> </ScrollViewer>

    //数据模板

    <DataTemplate x:Key="DataTemplate1"> <UserControl> <Grid Background="White"> <Image Source="{Binding wbmp}" Width="{Binding PageWidth}" Height="{Binding PageHeight}"/> </Grid> </UserControl> </DataTemplate>

    我已测试当wbmp的值为空时,内存泄漏现象也是存在的。
    请问我哪里出错了呢?谢谢!



    2012年4月20日 3:47

全部回复