Datagrid或者listview 中想要把相应的项 滚动到当前可见的位置, 必须满足2个条件:

1) 必须去掉虚拟化
     VirtualizingStackPanel.IsVirtualizing ="False"
2) 调用ScrollToView
       //Bring current selected item to view
            if(null != grdStudyList. SelectedItem && 0 != grdStudyList .Columns. Count)
            {
                //first focus the grid
                grdStudyList.Focus ();
                //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
                DataGridCellInfo cellInfo = new DataGridCellInfo(grdStudyList .SelectedItem, grdStudyList.Columns [0]);
                //set the cell to be the active one
                grdStudyList.CurrentCell = cellInfo;
                //scroll the item into view
                grdStudyList.ScrollIntoView (grdStudyList. SelectedItem);    
            }         
3)如果不去掉虚拟化, VirtualizingStackPanel.IsVirtualizing ="True"
则, 调用如下语句:
  private void ScrollItemInSelector (Selector dtg, object needScrollItem)
        {
            //Bring current selected item to view
            if (null == dtg && null != needScrollItem )
            {
                //first focus the grid
                dtg.Focus ();
                dtg.SelectedItem = needScrollItem;
                dtg.Items .MoveCurrentTo( needScrollItem);
                ScrollViewer scv = FindVisualChild< ScrollViewer>(dtg );
                if (null != scv
                    && ( dtg.Items .CurrentPosition < scv.VerticalOffset - scv. ViewportHeight || dtg.Items .CurrentPosition > scv.VerticalOffset + scv. ViewportHeight)
                    )
                {
                    scv.ScrollToVerticalOffset (dtg. Items.CurrentPosition );
                }
            }
        }
  

DataGrid 显示选中的item的更多相关文章

  1. silverlight DataGrid 显示篇

    silverlight DataGrid 显示篇 分类: Silverlight2012-05-12 21:55 693人阅读 评论(0) 收藏 举报 datagridsilverlightbindi ...

  2. android中设置ListView的选中的Item的背景颜色

    ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了,要实现放开鼠标后选择项的背景还是有颜色的. 1.配置main.xml <? ...

  3. angularjs中只显示选中的radio的值

    angularjs中,只显示选中的radio的值.主要是相同的radio,name属性值要相同还有ng-model的值要相同,同时要指定value值.这样选中的时候就会在下面的div中显示选中的值了. ...

  4. easyui datagrid显示进度条控制操作

    在当我们需要控制时间前台实际项目页面datagrid显示进度条的数据加载时运行,和datagrid默认情况下只在有url加载运行时的数据显示方式的进度条.下面的代码手动控制: 打开一个进度条: $(' ...

  5. vue2.0 element-ui中的el-select选择器无法显示选中的内容

    我使用的是element-ui V2.2.3.代码如下,当我选择值得时候,el-select选择器无法显示选中的内容,但是能触发change方法,并且能输出选择的值. select.vue文件 < ...

  6. tableview 选中一行后,不显示选中颜色

    tableview 选中一行后,不显示选中颜色 千万不要将tableview的allowsSelection设置成NO,那样的话可能导致tableview不能响应点击动作. 应该使用:cell.sel ...

  7. combobox无法显示选中的数据,都是undefined

    $('#firstfactor').combobox({                url: '@Url.Action("GetMultiAirFactor_Day_New", ...

  8. ViewPager一屏显示多个item,及边缘滑动事件优化

    关于ViewPager显示两边的item方法,网络上是方法都在ViewPager外包一个Layout, 然后设置ViewPager和外面的Layout的clipChildren="false ...

  9. C#中datagridview选中行后textbox显示选中的内容

    我想让datagridview中某一行被选中时,textbox中显示选中的值,datagridview的选中模式是整行:this.dataGridView1.SelectionMode = DataG ...

随机推荐

  1. Rate Monotonic Scheduling algorithm

    这篇文章写得不错 http://barrgroup.com/embedded-systems/How-To/RMA-Rate-Monotonic-Algorithm 另外rtems的官方文档也有类似说 ...

  2. netbeans xdebug

    xdebug配置 装了wamp后,xdebug默认就安装好了,为了能够用netbeans远程调试,配置文件里得加几句 [xdebug] xdebug.remote_enable = on xdebug ...

  3. git 工具 - 子模块(submodule)

    From: https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97 子模块 有种情况我们经常 ...

  4. IntelliJ IDEA打可执行jar包

    <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <config ...

  5. EntityFramwork 查询

    EntityFramwork 查询 1.简单查询: SQL: SELECT * FROM [Clients] WHERE Type=1 AND Deleted=0 ORDER BY ID EF: // ...

  6. EasyNVR摄像机H5流媒体服务器在windows上批处理脚本自动以管理员权限运行

    很多时候, 我们需要以管理员权限来运行批处理脚本, 比如操作 windows 服务. EasyNVR 中提供安装服务的批处理脚本, 运行这个bat文件, 自动将 EasyNVR 以 windows 服 ...

  7. 【CISCO强烈推荐】生成树 《路由协议》 卷一二 拥塞:网络延迟 阻塞:进程中 MTU QS:服务质量 OSPF RIP ISIS BGP 生成树 《路由协议》 卷一二

    协议 CP/IP路由技术第一卷 作    者 (美)多伊尔,(美)卡罗尔

  8. 【题解】Codeforces 961G Partitions

    [题解]Codeforces 961G Partitions cf961G 好题啊哭了,但是如果没有不小心看了一下pdf后面一页的提示根本想不到 题意 已知\(U=\{w_i\}\),求: \[ \s ...

  9. Linux搭建FTP服务器实战

    首先准备一台Linux系统机器(虚拟机也可), 检测出是否安装了vsftpd软件: rpm -qa |grep vsftpd 如果没有输出结果,就是没有安装. 使用命令安装,安装过程中会有提示,直接输 ...

  10. 后缀自动机的python实现

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-02-25 14:32:50 # @Author : Sheldon (thi ...