【发布时间】:2012-05-23 01:56:03
【问题描述】:
我在 Silverlight 4 的用户控件中为数据网格动态创建列,该控件工作正常。 数据网格的第一列是一个按钮,因此我使用以下代码为 DataGrid 添加 DataTemplate:
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Search";
StringBuilder sb = new StringBuilder();
sb.Append("<DataTemplate ");
sb.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
sb.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>");
sb.Append("<Button Name='searchBtn' Width='25' Height='20' Click='performFastSearch' >");
sb.Append("<Image Source='http://localhost/SiteAssets/img/Homepage/ribbon_top_right.png' Stretch='None' />");
sb.Append("</Button>");
sb.Append("</DataTemplate>");
templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(sb.ToString());
如果我将 Click="performFastSearch" 部分保留在外,但在添加时会因“crossappdomainmarshaledexception”而中断,则该代码有效。
这是我应该尝试添加点击处理程序方法还是应该使用其他方法?
【问题讨论】:
标签: silverlight button silverlight-4.0 datagrid