Page view counter
Nullable(Of T) Dependency Property Issues Subscribe to this thread
Last post 09-29-2008 1:27 AM by Yi-Lun Luo - MSFT. 1 replies.
Sort Posts:
09-25-2008 3:18 PM
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 Applications Developer
My Blog = Mostly Developers

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

wjchristenson2

Loading...
Joined on 09-04-2008
USA
Posts 45
09-29-2008 1:27 AM
Marked as Answer
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.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,747
Microsoft Communities