使用Silverlight 3.0动态创建DataTemplate时获取未处理的异常
需求是创建一个可重用的多选组合框自定义控件。为此,我通过代码动态创建DataTemplate,并设置combobox ItemTemplate。我能够动态加载datatemplate并设置ItemTemplate,但在选择combobox时会出现未处理的异常(代码:7054) 这是密码使用Silverlight 3.0动态创建DataTemplate时获取未处理的异常,silverlight,silverlight-3.0,datatemplate,Silverlight,Silverlight 3.0,Datatemplate,需求是创建一个可重用的多选组合框自定义控件。为此,我通过代码动态创建DataTemplate,并设置combobox ItemTemplate。我能够动态加载datatemplate并设置ItemTemplate,但在选择combobox时会出现未处理的异常(代码:7054) 这是密码 Class MultiSelCombBox: ComboBox { public override void OnApplyTemplate() { base.OnApplyT
Class MultiSelCombBox: ComboBox
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
CreateTemplate();
}
void CreateTemplate()
{
DataTemplate dt = null;
if (CreateItemTemplate)
{
if (string.IsNullOrEmpty(CheckBoxBind))
{
dt = XamlReader.Load(@"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name=""DropDownTemplate""><Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name=""CheckboxGrid""><TextBox xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name=""test"" xml:space=""preserve"" Text='{Binding " + TextContent + "}'/></Grid></DataTemplate>") as DataTemplate;
this.ItemTemplate = dt;
}
}
}
//Other code goes here }}
Class multiselcombox:ComboBox
{
应用程序模板()上的公共重写无效
{
base.OnApplyTemplate();
CreateTemplate();
}
void CreateTemplate()
{
数据模板dt=null;
如果(CreateItemTemplate)
{
if(string.IsNullOrEmpty(CheckBoxBind))
{
dt=XamlReader.Load(@“”)作为数据模板;
this.ItemTemplate=dt;
}
}
}
//其他代码在这里}}
我做错了什么?建议?错误。。代码中的错误。不应该在每个元素上重新定义名称空间。仅顶部元素