Skip to main content

Microsoft Silverlight

Answered Question Nullable(Of T) Dependency Property IssuesRSS Feed

(0)

wjchristenson2
wjchrist...

Member

Member

104 points

51 Posts

Nullable(Of T) Dependency Property Issues

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
 

 

 

Bill - Senior .NET Developer
A Mostly Developers Blogger

Please remember to click “Mark as Answer” on the post that helps you.

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Nullable(Of T) Dependency Property Issues

Unfortunately XAML doesn't support Nullable types because they're generic types...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

StefanOlson
StefanOlson

Member

Member

215 points

90 Posts

Re: Nullable(Of T) Dependency Property Issues

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

http://www.olsonsoft.com/blogs/stefanolson
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities