码迷,mamicode.com
首页 > Windows程序 > 详细

一、WPF 2个datagrid之间同步进度条

时间:2019-04-03 12:45:16      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:viewer   visible   ica   wpf   src   代码   bsp   invoke   进度   

页面代码

技术图片
            <Grid DockPanel.Dock="Left" Width="400">
                <DataGrid Name="dgSource" VerticalScrollBarVisibility="Visible"  EnableRowVirtualization="False" ScrollViewer.ScrollChanged="DgSource_ScrollChanged" >
                     
                </DataGrid>
            </Grid>
            <Grid>
                <DataGrid Name="dgTo"   VerticalScrollBarVisibility="Visible" EnableRowVirtualization="False" ScrollViewer.ScrollChanged="DgTo_ScrollChanged">
                   
                </DataGrid>
            </Grid>
View Code

后端代码

技术图片
 1   private void DgTo_ScrollChanged(object sender, ScrollChangedEventArgs e)
 2         {
 3             ScrollChanged(dgTo, dgSource, e);
 4         }
 5 
 6         void ScrollChanged(DataGrid dg1, DataGrid dg2, ScrollChangedEventArgs e)
 7         {
 8             if (e.HorizontalChange != 0.0f)
 9             {
10                 ScrollViewer sv = null;
11                 Type t = dg1.GetType();
12                 try
13                 {
14                     sv = t.InvokeMember("InternalScrollHost", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, dg2, null) as ScrollViewer;
15                     sv.ScrollToHorizontalOffset(e.HorizontalOffset);
16                 }
17                 catch (Exception ex)
18                 {
19                     MessageBox.Show(ex.Message);
20                 }
21             }
22             if (e.VerticalChange != 0.0f)
23             {
24                 ScrollViewer sv = null;
25                 Type t = dg1.GetType();
26                 try
27                 {
28                     sv = t.InvokeMember("InternalScrollHost", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, dg2, null) as ScrollViewer;
29                     sv.ScrollToVerticalOffset(e.VerticalOffset);
30                 }
31                 catch (Exception ex)
32                 {
33                     MessageBox.Show(ex.Message);
34                 }
35             }
36 
37         }
38 
39         private void DgSource_ScrollChanged(object sender, ScrollChangedEventArgs e)
40         {
41             ScrollChanged(dgSource, dgTo, e);
42         }
View Code

 

一、WPF 2个datagrid之间同步进度条

标签:viewer   visible   ica   wpf   src   代码   bsp   invoke   进度   

原文地址:https://www.cnblogs.com/cvol/p/10647793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!