Skip to main content

Microsoft Silverlight

Property Element Syntax with Custom Controls?RSS Feed

(0)

wkamir
wkamir

Member

Member

2 points

4 Posts

Property Element Syntax with Custom Controls?

Hi Silverlight Enthusiasts :)

I tried to spice up my custom control a little and exposed another property named 'Background' which routes through to the canvas's background...

public Brush Background
{
get { return root.Background; }
set { root.Background = value; }
}

Trying to set the property in xaml:

<slControls:MyLabel x:Name="MyControl" Text="Hello Label" Foreground="Black" >

<slControls:MyLabel.Background>

<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">

<GradientStop Offset="0" Color="Yellow" />

<GradientStop Offset="1" Color="Green" />

</LinearGradientBrush>

</slControls:MyLabel.Background>

</slControls:MyLabel>

throws an error. Of course if i omit the slControls prefix at the Background Property Element, it still does'nt work... anyone here who knows how to do this? Or is this just plain impossible with custom silverlight controls?

Best regards,
Wolfgang

jasonxz
jasonxz

Participant

Participant

1750 points

529 Posts

Re: Property Element Syntax with Custom Controls?

The problem, here, is that the syntax you're using in XAML to define the Background only works for dependency properties.  If you, instead, used "Background='"Black'", it should work.  Unfortunately, there's no way to create a Gradient background with that method and there's no way, yet, to create your own dependency property.

The only way I know of around all of this is to have your custom control inherit from Canvas instead of Control.  Then, you could use Canvas.Background.

wkamir
wkamir

Member

Member

2 points

4 Posts

Re: Property Element Syntax with Custom Controls?

Oh bummer :( that renders custom controls kind of useless... or at least really limits their usefulness.

Thanks for the hint though!

jasonxz
jasonxz

Participant

Participant

1750 points

529 Posts

Re: Property Element Syntax with Custom Controls?

Well, hopefully, we'll get the ability to create our own dependency properties by the time SL goes live and that will fix this problem.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities