代码之家  ›  专栏  ›  技术社区  ›  Scott

Silverlight TabControl继承在Expression Blend中失败

  •  1
  • Scott  · 技术社区  · 15 年前

    我创建了一个基本 模板化控件 通过Visual Studio。然后我继承 选项卡控件 而不是控制。它在技术上可以工作(即通过编译),但在表达式Blend 3中,我得到一个错误“对象引用未设置为对象的实例”。

    那么,如果我单击tabitem本身,错误就消失了?有人经历过吗?

    我在一个全新的项目上测试了它,除了一个自定义的选项卡控件之外,没有其他任何东西,同样的事情也会发生(所以它很可能是一个表达式错误?)

    代码在这里:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace Riagenic.UXLib.Controls.Chrome
    {
        public class ChromeTabControl : TabControl
        {
            public ChromeTabControl() : base()
            {
                this.DefaultStyleKey = typeof(ChromeTabControl);
    
            }
        }
    }
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Scott    15 年前

    原来是ExpressionBlend 3中的一个bug。解决方法(通过ExpressionBlend和Rockstar的项目经理PeterBlois)说,要将这一点落实到位:

    这似乎是混合3-i中的一个错误 可以在混合3中重新调制,但不能在我们的 最近的版本。它试图 查找SelectedIndexProperty静态 在自定义TabControl上失败。

    解决方法是添加代码(而不是 非常理想,因为您将得到解析 警告):

    namespace Riagenic.UXLib.Controls.Chrome {
          public class ChromeTabControl : TabControl {
                public ChromeTabControl()
                      : base() {
                      this.DefaultStyleKey = typeof(ChromeTabControl);
    
                }
    
                public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register("SelectedIndex", typeof(int), typeof(ChromeTabControl), new PropertyMetadata(0));
          }
    }