silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

        在Silverlight中的DataGrid控件使用中我们想点击其中一行并且看这一行的详细信息应该如何做呢?而且这个详细信息是多行的数据,而非简单的几个属性。         在这里我们使用DataGrid.RowDetailsTemplate来设置或者获取行详细信息。首先我们准备一个DataGrid命名为A,设置其 RowDetailsVisibilitymode="Visibl

        在Silverlight中的DataGrid控件使用中我们想点击其中一行并且看这一行的详细信息应该如何做呢?而且这个详细信息是多行的数据,而非简单的几个属性

        在这里我们使用DataGrid.RowDetailstemplate来设置或者获取行详细信息。首先我们准备一个DataGrid命名为A,设置其 RowDetailsVisibilitymode="VisibleWhenSELEcted" (行详细信息模板的显示模式是当这行被选中的时候展开这行的详细信息。)然后再为A设置DataGrid.RowDetailstemplate模板,并 且在这个模板中添加一个DataGrid命名为B,这就是前台的XAML代码,在后台中我们设置一个实体集AList绑定到A的DataGrid,然后在 AList实体集中有一个属性是BList,这个就是多行的详细信息。将BList详细信息字段绑定到B的DataGrid控件的Itemssource 即可。

        下面我们来看看这个简单的应用技巧的Xaml代码如下:

 

 
 
  1. <Grid x:Name="LayoutRoot" BACkground="White"
  2.         <!--这里是第一个DataGrid,其DataGrid.RowDetailstemplate模板会绑定另外一个DataGrid以显示其详细信息--> 
  3.         <sdk:DataGrid x:Name="gridemployee" CanUserReordercolumns="false" CanUserSortcolumns="false"  
  4.                         rowDetailsVisibilitymode="VisibleWhenSELEcted"  
  5.                         HorizontalAlignment="Center" ScrollViewer.VerticalScrollBarVisibility="Auto"  
  6.                         Height="200"  AutoGeneratecolumns="false" Width="422" VerticalAlignment="Center"
  7.         <sdk:DataGrid.columns> 
  8.             <sdk:DataGridTextcolumn Width="150"  
  9.                                         Header="用户名"  
  10.                                         Binding="{Binding UserNamE}"/> 
  11.             <sdk:DataGridTextcolumn Width="150"  
  12.                                         Header="用户密码"  
  13.                                         Binding="{Binding UserPwD}"/> 
  14.         </sdk:DataGrid.columns> 
  15.         <sdk:DataGrid.RowDetailstemplate> 
  16.             <DataTemplate> 
  17.                 <!--这里是第二个DataGrid显示详细信息--> 
  18.                 <sdk:DataGrid  AutoGeneratecolumns="false" Itemssource="{Binding UserDetailInfomation}" 
  19.                                 HeadersVisibility="None"
  20.                     <sdk:DataGrid.columns> 
  21.                         <sdk:DataGridTextcolumn Width="100"  
  22.                                         Header="地址"  
  23.                                         Binding="{Binding UserAddress}"/> 
  24.                         <sdk:DataGridTextcolumn Width="100"  
  25.                                         Header="城市"  
  26.                                         Binding="{Binding UserCity}"/> 
  27.                         <sdk:DataGridTextcolumn Width="100"  
  28.                                         Header="国籍"  
  29.                                         Binding="{Binding UserCountry}"/> 
  30.                         <sdk:DataGridTextcolumn Width="100"  
  31.                                         Header="类型"  
  32.                                         Binding="{Binding UserStatE}"/> 
  33.                     </sdk:DataGrid.columns> 
  34.                 </sdk:DataGrid> 
  35.             </DataTemplate> 
  36.         </sdk:DataGrid.RowDetailstemplate> 
  37.     </sdk:DataGrid> 
  38. </Grid> 
@H_772_331@

        然后我们来看看他的数据源的Xaml.cs代码如下:

 

 
 
  1. public partial class MainPage : UserControl 
  2.  { 
  3.      public MainPage() 
  4.      { 
  5.          InitializeComponent(); 
  6.          this.gridemployee.Itemssource = new UserInfo().GetemployeeData(); 
  7.      } 
  8.  } 
  9.  /// <sumMary
  10.  /// 用户信息 
  11.  /// </sumMary
  12.  public class UserInfo 
  13.  { 
  14.      public String UserName { get; set; } 
  15.      public String UserPwd { get; set; } 
  16.      /// <sumMary
  17.      /// 用户详细信息 
  18.      /// </sumMary
  19.      public List<UserDetailInfo> UserDetailInfomation{get;set;} 
  20.      public UserInfo() 
  21.      { } 
  22.      /// <sumMary
  23.      /// 获取用户信息的实例 
  24.      /// </sumMary
  25.      /// <returns></returns
  26.      public List<UserInfo> GetemployeeData() 
  27.      { 
  28.          List<UserInfo> employees = new List<UserInfo>(); 
  29.          employees.Add 
  30.              ( 
  31.              new UserInfo 
  32.              { 
  33.                  UserName = "李伟"
  34.                  UserPwd = "1333821"
  35.                  UserDetailInfomation = new List<UserDetailInfo>()  
  36.                  {  
  37.                      new UserDetailInfo() 
  38.                      {  
  39.                              UserAddress="四川省成都市"
  40.                              UserCity="成都"
  41.                              UserCountry="中国"
  42.                              UserState="当前所在地" 
  43.                      }, 
  44.                          new UserDetailInfo() 
  45.                      {  
  46.                              UserAddress="四川省内江市"
  47.                              UserCity="内江"
  48.                              UserCountry="中国"
  49.                              UserState="出生地" 
  50.                      
  51.                  } 
  52.              }); 
  53.          employees.Add 
  54.              ( 
  55.              new UserInfo 
  56.              { 
  57.                  UserName = "Json"
  58.                  UserPwd = "json282"
  59.                  UserDetailInfomation = new List<UserDetailInfo>()  
  60.                  {  
  61.                      new UserDetailInfo() 
  62.                      {  
  63.                              UserAddress="广东省广州市"
  64.                              UserCity="广州"
  65.                          new UserDetailInfo() 
  66.                      {  
  67.                              UserAddress="广东省茂名市"
  68.                              UserCity="茂名"
  69.                              UserState="出生地" 
  70.                      
  71.                  } 
  72.              }); 
  73.          employees.Add 
  74.              ( 
  75.              new UserInfo 
  76.              { 
  77.                  UserName = "刘敏"
  78.                  UserPwd = "motorola"
  79.                  UserDetailInfomation = new List<UserDetailInfo>()  
  80.                  {  
  81.                      new UserDetailInfo() 
  82.                      {  
  83.                              UserAddress="湖南省长沙市"
  84.                              UserCity="长沙"
  85.                          new UserDetailInfo() 
  86.                      {  
  87.                              UserAddress="湖南省长沙市"
  88.                              UserCity="长沙"
  89.                              UserState="出生地" 
  90.                      
  91.                  } 
  92.              }); 
  93.          return employees; 
  94.      } 
  95.  } 
  96.  /// <sumMary
  97.  /// 用户详细信息的实体 
  98.  /// </sumMary
  99.  public class UserDetailInfo 
  100.  { 
  101.      public String UserAddress { get; set; } 
  102.      public String UserCity { get; set; } 
  103.      public String UserState { get; set; } 
  104.      public String UserCountry { get; set; } 
  105.  } 
@H_772_331@

        最后我们来看看它的运行@L_874_32@,如果需要源码请点击SLDataGridRowDetail.zip下载。

Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate

Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate

大佬总结

以上是大佬教程为你收集整理的Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate全部内容,希望文章能够帮你解决Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。