silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了silverlight之How To:设置ComboBox控件的数据源当ComboBox用来作为DataGrid的某列的编辑控件时大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

DataGrid是个可编辑的列表控件,而且可以用已有的输入控件来作为某一列的编辑控件,比如用ComboBox控件来作为某列的编辑控件供用户选择数据,这个时候就要先设置好ComboBox控件的下拉列表项了,在silverlight里怎么做呢? 首先,定义好XAML,如下:   <data:DataGrid Grid.Row="0" x:Name="gridVariables" rowHeight="

DataGrid是个可编辑的列表控件,而且可以用已有的输入控件来作为某一列的编辑控件,比如用ComboBox控件来作为某列的编辑控件供用户选择数据,这个时候就要先设置好ComboBox控件的下拉列表项了,在silverlight里怎么做呢?

首先,定义好XAML,如下:

 

  1. <data:DataGrid Grid.Row="0" x:Name="gridVariables" RowHeight="20" AutoGeneratecolumns="false" BorderThickness="1,1,1">
  2.                         <data:DataGrid.columns>
  3.                             <data:DataGridTemplatecolumn Header="类型" Width="120">
  4.                                 <data:DataGridTemplatecolumn.CellTemplate>
  5.                                     <DataTemplate>
  6.                                         <TextBlock Text="{Binding TypE}"/>
  7.                                     </DataTemplate>
  8.                                 </data:DataGridTemplatecolumn.CellTemplate>
  9.                                 <data:DataGridTemplatecolumn.CellEdiTingTemplate>
  10.                                     <DataTemplate>
  11.                                         <ComboBox >
  12.                                         </ComboBox>
  13.                                     </DataTemplate>
  14.                                 </data:DataGridTemplatecolumn.CellEdiTingTemplate>
  15.                             </data:DataGridTemplatecolumn>
  16.                        </data:DataGrid.columns>
  17.                     </data:DataGrid>

其次,需要定义一个类并由该类的一个属性来提高选项数据来源,如下:

  1. public class WorkflowVariableTypes
  2.     {
  3.         public List<WorkflowVariableType> WorkflowVariableTypeList
  4.         {
  5.             get
  6.             {
  7.                 List<WorkflowVariableType> types = new List<WorkflowVariableType>();
  8.                 for (int i = 0; i < 14; i++)
  9.                 {
  10.                     types.Add(new WorkflowVariableType {Type = (VariableTypE)i });
  11.                 }
  12.                 return types;
  13.             }
  14.         }
  15.     }

然后,我们就可以通过用户控件资源的方式声明该类的一个实例,如下:

  1. <UserControl.resources>
  2.         <local:WorkflowVariableTypes x:Key="workflowVariableTypes" />
  3.     </UserControl.resources>

 

最后,就是使用该资源了,如下:

这个过程有些类似格式化DataGrid里的列数据,而且我们也可获得一个经验,那就是用户控件的资源是个很强大的东西,可以用来引用静态的东西(图片,样式等),也可以引用动态的东西(代码,类)。

@H_674_549@

大佬总结

以上是大佬教程为你收集整理的silverlight之How To:设置ComboBox控件的数据源当ComboBox用来作为DataGrid的某列的编辑控件时全部内容,希望文章能够帮你解决silverlight之How To:设置ComboBox控件的数据源当ComboBox用来作为DataGrid的某列的编辑控件时所遇到的程序开发问题。

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

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