Skip to main content

Microsoft Silverlight

Answered Question Color element in XAML results in NullReferenceExceptionRSS Feed

(0)

arrgh
arrgh

Member

Member

21 points

14 Posts

Color element in XAML results in NullReferenceException

I've was working on a color picker control when I came across this problem.  Here is the simplest example.  The following causes an exception:

     <Rectangle>
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="255" R="255" G="255" B="255" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
While this does not:
     <Rectangle>
<Rectangle.Fill>
<SolidColorBrush Color="#FFFFFFFF">
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>


I'd hoped to use template binding for the red / green / blue values in my control, which is why the second markup would be unsuitable.

davidezordan
davidezo...

Contributor

Contributor

5614 points

863 Posts

Silverlight MVP

Re: Color element in XAML results in NullReferenceException

Hi,

if you set the Color properties in code behind it works.

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts

arrgh
arrgh

Member

Member

21 points

14 Posts

Re: Color element in XAML results in NullReferenceException

 Hi Davide,

 Thanks for answering.  I realize it works in code, and will work around this some other way.  However it still is a bug that should be addressed as it prevents you from using it in a control template like I'm doing.

davidezordan
davidezo...

Contributor

Contributor

5614 points

863 Posts

Silverlight MVP

Re: Re: Color element in XAML results in NullReferenceException

Yes, I agree with you.

Thanks, Davide

Silverlight MVP

Blog Twitter Silverlight Experts

Mog Liang - MSFT
Mog Lian...

Star

Star

14812 points

1,417 Posts

Answered Question

Re: Color element in XAML results in NullReferenceException

Hi, arrgh

I use the latest silverlight build to run your code, it displayed as expected, this issue has been fixed.

thanks.

Mog Liang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

arrgh
arrgh

Member

Member

21 points

14 Posts

Re: Color element in XAML results in NullReferenceException

Thanks Mog.  It's nice to know this is resolved in SL3 (unfortunately I'm stuck with SL2 for now!).

Cheers.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities