zoukankan      html  css  js  c++  java
  • GridView.ScrollIntoView() doesn't work

    I am writing an application which contains two pages, GroupedItemsPage and ItemDetailPage. I let lots of pictures present in the GroupItemsPage, then after select a specified picture in this page, it will nevigate the the second page withe the details showing for the selected picture. Since I put too much pictures in the first page, therefore the gridview always put the top picutres into view each time I goback to the first page. even the picture I selected previously are the last picture which need a scroll to the end.

    I tried to use GridView.ScrollIntoView() in the LoadState method, my codes like below.

    protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
            {
                // TODO: Create an appropriate data model for your problem domain to replace the sample data
                var sampleDataGroups = SampleDataSource.GetGroups((String)navigationParameter);
                this.DefaultViewModel["Groups"] = sampleDataGroups;
    
                if (pageState!=null&&pageState.ContainsKey("SelectedItem"))
                {
                    SelectedItemId = pageState["SelectedItem"].ToString ();                var sampleDataItem = SampleDataSource.GetItem(SelectedItemId);
                    //SampleDataGroup group = ((SampleDataItem)sampleDataItem).Group;
                    //groupedItemsViewSource.View.MoveCurrentTo(group);
    
                    itemGridView.ScrollIntoView(sampleDataItem);   
                }
            }

    however, nomatter what I do, it just doesn't work.

    then I moved the method call to Loaded event like below. It works:

      public GroupedItemsPage()
            {
                this.InitializeComponent();
                Loaded += GroupedItemsPage_Loaded;
            }
    
            void GroupedItemsPage_Loaded(object sender, RoutedEventArgs e)
            {
                if (SelectedItemId!=null&&SelectedItemId != string.Empty)
                {
                    var sampleDataItem = SampleDataSource.GetItem(SelectedItemId);
                    //SampleDataGroup group = ((SampleDataItem)sampleDataItem).Group;
                    //groupedItemsViewSource.View.MoveCurrentTo(group);
    
                    itemGridView.ScrollIntoView(sampleDataItem);    
                }
            }
  • 相关阅读:
    springmvc学习笔记---idea创建springmvc项目
    Spring Boot中使用Swagger2构建RESTful API文档
    Dubbo原理实现之使用Javassist字节码结束构建代理对象
    Dubbo启动时服务检查
    Dubbo原理实现之代理接口的定义
    dubbo实现原理之动态编译
    Dubbo实现原理之基于SPI思想实现Dubbo内核
    dubbo实现原理之SPI简介
    Spring中使用StandardServletMultipartResolver进行文件上传
    SpringCloud之Feign
  • 原文地址:https://www.cnblogs.com/qixue/p/2818967.html
Copyright © 2011-2022 走看看