Archive for April 2008
Dependency Property Annoyance
While I’m in the blogging mood, can you spot the bug with the code below?
public static readonly DependencyProperty MyCoolProperty = DependencyProperty.Register("MyCool",
typeof(double),
typeof(MyCoolObject),
new FrameworkPropertyMetadata(0));
It’s not an obvious problem and unless you’re really into WPF it’s even less obvious. The problem is that when setting the default value of 0 (zero). The framework rightfully assumes it should be an int, but it will throw an exception when it tries to assign it to the associated dependency property during runtime. Why? Because it cannot implicitly convert the int type to a double type.To fix it you need to declare the dependency property like (notice the 0.0 in place of the 0):
public static readonly DependencyProperty MyCoolProperty = DependencyProperty.Register("MyCool",
typeof(double),
typeof(MyCoolObject),
new FrameworkPropertyMetadata(0.0));
Apologies…
I’ve been a bit busy since the holidays and haven’t had time to maintain my blog. I’ve received a few requests to continue the “Class of the Week” series, which I’m hoping to do.
I’ve been working in WPF heavily lately and so far I’m a fan. There are definitely some gotchas that are non-obvious and extremely hard to debug. Luckily there are alot of resources out there, such as CodeProject and numerous blogs.
I’ve been working with Actipro’s WPF Studio, which is top notch and they churn out new controls at a pretty fast pace (check out what’s coming). The also provide the ever helpful WPFpedia.com, which organizes alot of various WPF resources.
Like I said, hopefully I can find the time to start blogging again. Not that it takes a huge amount of my time