Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Nullable(Of T) Dependency Property Issues
2 replies. Latest Post by StefanOlson on July 20, 2009.
(0)
wjchrist...
Member
104 points
51 Posts
09-25-2008 3:18 PM |
I am trying to create dependency properties that utilize the Nullubale(Of T) structure. When I set the property in XAML, I get parser exceptions.
For instance, I have a user control and I may or may not want to set its color. If I don't set its color, I want t auto-color it using a predefined color. This would be easy using the Nullable(Of T) structure because I could simply do a test on the property like so: Me.Color.HasValue. I've tried explicitly defining a type converter attribute on my properties to no avail. Any ideas?
Public Shared ReadOnly ColorProperty As DependencyProperty = DependencyProperty.Register("Color", GetType(Nullable(Of Color)), GetType(Series), Nothing) <ComponentModel.TypeConverterAttribute(GetType(Nullable(Of Color)))> _ Public Property Color() As Nullable(Of Color) Get Return CType(GetValue(Series.ColorProperty), Nullable(Of Color)) End Get Set(ByVal value As Nullable(Of Color)) SetValue(Series.ColorProperty, value) End Set End Property
Yi-Lun L...
All-Star
25052 points
2,747 Posts
09-29-2008 1:27 AM |
Unfortunately XAML doesn't support Nullable types because they're generic types...
StefanOlson
215 points
90 Posts
07-20-2009 12:20 AM |
Yi-Lun Luo - MSFT: Unfortunately XAML doesn't support Nullable types because they're generic types...
Strictly speaking, it's Silverlight that doesn't support these types because the xaml in WPF does in fact support nullable types. The fact that Silverlight doesn't support them is frustrating.
...Stefan