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
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.
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.
I second this ... this is totally ridiculous. I had a class to be used in XAML and suddenly I go to set a simple "bool" value and suddenly get some completely useless parser errors.
____________________________________________________________________________
To repeat what others have said, requires education; to challenge it, requires brains.
Mary Pettibone Poole, A Glass Eye at a Keyhole, 1938
---
jamonjoo.com
wjchristenson2
Member
104 Points
51 Posts
Nullable(Of T) Dependency Property Issues
Sep 25, 2008 07:18 PM | LINK
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?
A Mostly Developers Blogger
Please remember to click “Mark as Answer” on the post that helps you.
Yi-Lun Luo -...
All-Star
25149 Points
2759 Posts
Microsoft
Re: Nullable(Of T) Dependency Property Issues
Sep 29, 2008 05:27 AM | LINK
Unfortunately XAML doesn't support Nullable types because they're generic types...
StefanOlson
Member
260 Points
139 Posts
Re: Nullable(Of T) Dependency Property Issues
Jul 20, 2009 04:20 AM | LINK
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
jamesnw
Member
137 Points
81 Posts
Re: Re: Nullable(Of T) Dependency Property Issues
Mar 26, 2010 12:24 AM | LINK
I second this ... this is totally ridiculous. I had a class to be used in XAML and suddenly I go to set a simple "bool" value and suddenly get some completely useless parser errors.
To repeat what others have said, requires education; to challenge it, requires brains.
Mary Pettibone Poole, A Glass Eye at a Keyhole, 1938
---
jamonjoo.com