当前位置: 移动技术网 > IT编程>开发语言>.net > WPF学习笔记(4):获取DATAGRIDTEMPLATECOLUMN模板定义的内容控件

WPF学习笔记(4):获取DATAGRIDTEMPLATECOLUMN模板定义的内容控件

2019年01月12日  | 移动技术网IT编程  | 我要评论

战雷神下载,簿熙来,快青8cj

在之前的datagrid的datagridtemplatecolumn列中,自定义了一个textbox控件,但是在c#代码中提示找不到这个控件,导致无法对该控件进行操作。在网上搜索后,发现一些处理方法比较繁琐,下面这个方法最简便。

xaml格式描述:

 1 <datagrid name="datagrid" grid.row="1" itemssource="{binding}"  >
 2        <datagrid.columns>
 3             <datagridtemplatecolumn header="描述">
 4                     <datagridtemplatecolumn.celltemplate>
 5                         <datatemplate>
 6                             <expander x:name="expander" header="{binding describe}">
 7                                 <textblock text="{binding path=exception}" textwrapping="wrap" minheight="30"  minwidth="250" />
 8                             </expander>
 9                         </datatemplate>
10                     </datagridtemplatecolumn.celltemplate>
11               </datagridtemplatecolumn>
12        </datagrid.columns>
13 </datagrid>

现在要获取expander控件,代码如下:

1 int index = datagrid.currentcell.column.displayindex;
2 datagridtemplatecolumn templecolumn = datagrid.columns[index] as datagridtemplatecolumn;
3 
4 if(templecolumn == null) return;
5 
6 object item = datagrid.currentcell.item;
7 frameworkelement element = templecolumn.getcellcontent(item);
8 expander expander= templecolumn.celltemplate.findname("expander", element);

 

原贴地址:

原作者:烟灰缸

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网