Silverlight TabControl Inheritance Fails in Expression Blend
I create a basic TemplatedControl via Visual Studio. I then inherit TabControl instead of Control. It technically works (ie passes compile) but inside Expression Blend 3, I get an error " object reference not set to an instance of an object".
Then if i click on the TabItem itself, the error goes away? anyone experience this?
I tested this out on a brand new project with nothing it other than a custom tab control and same thing happens (so it could very well be an expression bug?)
Code is here:
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);
}
}
}
It turns out it was a bug in Expression Blend 3. Work around (Via Peter Blois - Program Manager on Expression Blend and rockstar) says to put this in place:
This appears to be a bug in Blend 3- I can repro in Blend 3 but not in our more recent builds. It’s trying to find the SelectedIndexProperty static on your custom TabControl and failing.
A workaround is to add the code (not ideal since you’ll get parse warnings):
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));
}
}
精彩评论