开发者

Getting unhandled exception when DataTemplate is created dynamically using Silverlight 3.0

Requirement is to cre开发者_运维百科ate 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜