WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法

WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法
原文: WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法

WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法

       最近在做一个项目,其中要用到主从表数据的折叠和隐藏,并且对从表中的数据能够获取和操作,虽然搞了好久,但最终被我推敲出来了,写出来分享一下,让朋友少走弯路,废话不说了,先上效果图:

下面是代码:

 
前台   
"{Binding}" Name= "dataGrid1" MouseUp= "dataGrid1_MouseUp" ...>   
   
                    "Auto" >   
                           
                               
                                "Expander_Expanded" Collapsed= "Expander_Collapsed" />   
                               
                           
                       
                    "{Binding Facility_type}" FontSize= "22" Header= "設備類型"   Width= "120" />   
                    "22" Header= "廠房代碼" Width= "85" />   
                    "22"  Header= "樓層" Width= "70" />   
                    "22"   Header= "部門名稱" Width= "430" />   
                    "{Binding Count_all}" FontSize= "22"    Header= "設備總數"  Width= "100" />   
                    "{Binding Count_no}" FontSize= "25"  FontWeight= "Bold"   Foreground= "Red" Header= "未使用數量"  Width= "115" />   
                    "{Binding Count_yes}" FontSize= "22"  Foreground= "Green"  Header= "使用中數量"  Width= "115" />   
         
                   
                   
                       
         
                        "dataGrid2"  Width= "1070"  SelectedValuePath = "dept_code" IsReadOnly= "True"  HeadersVisibility= "None" HorizontalGridLinesBrush= "#FFE0E2DF" VerticalGridLinesBrush= "#FFE0E2DF"
                                  ItemsSource= "{Binding Details}" CanUserAddRows= "False" SelectionUnit= "FullRow"  AutoGenerateColumns= "False"  MouseUp= "dataGrid2_MouseUp" >   
                               
                                ""   Width= "150" />   
                                "{Binding building_code}" FontSize= "22" Header= "廠房代碼" Width= "85" />   
                                "{Binding floor}" FontSize= "22"  Header= "樓層"

你可能感兴趣的:(WPF 实现主从的datagrid以及操作rowdetailtemplate 的方法)