Getting unhandled exception when DataTemplate is created dynamically using Silverlight 3.0

Posted by Bhaskar on Stack Overflow See other posts from Stack Overflow or by Bhaskar
Published on 2010-05-05T11:56:37Z Indexed on 2010/05/05 12:38 UTC
Read the original article Hit count: 252

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about datatemplate

Related posts about Silverlight