views:

61

answers:

1

Requirement is to create a reusable multi-select combobox custom control. To accomplish this, I am creating the DataTemplate dynamically through code and set the combobox ItemTemplate. I am able to load the datatemplate dynamically and set the ItemTemplate, but getting unhandled exception (code: 7054) when combobox is selected.

Here is the code

 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 }}

what am i doing wrong? suggestion?

A: 

err.. mistake in the code. shouldn't redefine namespaces on each element. Top element only.

Bhaskar