Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Silverlight 3.0动态创建DataTemplate时获取未处理的异常_Silverlight_Silverlight 3.0_Datatemplate - Fatal编程技术网

使用Silverlight 3.0动态创建DataTemplate时获取未处理的异常

使用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

需求是创建一个可重用的多选组合框自定义控件。为此,我通过代码动态创建DataTemplate,并设置combobox ItemTemplate。我能够动态加载datatemplate并设置ItemTemplate,但在选择combobox时会出现未处理的异常(代码:7054)

这是密码

 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;
}
}
}
//其他代码在这里}}

我做错了什么?建议?

错误。。代码中的错误。不应该在每个元素上重新定义名称空间。仅顶部元素