Skip to main content

Microsoft Silverlight

Unanswered Question ContentPropertyAttribute in Silverlight?RSS Feed

(0)

psih128
psih128

Member

Member

8 points

6 Posts

ContentPropertyAttribute in Silverlight?

is there an equivalent for WPF ContentPropertyAttribute in Silverlight clr?

I mean I'm creating some custom control. the control contains a custom children collection. I want the xaml reader to add xaml children to that collection. so instead of

<control> 

<control.children>

<child1 /> 

<child2 />

<child3 />

<control.children>

</control>

 

I want to be able to write  

 

 

<control> 

<child1 /> 

<child2 />

<child3 />

</control>

 

Mark Rideout
Mark Rid...

Contributor

Contributor

2357 points

273 Posts

MicrosoftModerator

Re: ContentPropertyAttribute in Silverlight?

We do not support [edit] custom content properties in the current 1.1 Alpha release. We are looking at how best to expose later.

-mark
Program Manager
Microsoft
This post is provided "as-is"


psih128
psih128

Member

Member

8 points

6 Posts

Re: ContentPropertyAttribute in Silverlight?

 Hm.... Im wondering then how does XamlReader know that it should add <Canvas>'s xaml tag children to Canvas.Children collection?

bryant
bryant

Star

Star

9927 points

1,629 Posts

Silverlight MVP

Re: ContentPropertyAttribute in Silverlight?

The restriction only applies to custom controls, not to Silverlight native objects.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

wjchristenson2
wjchrist...

Member

Member

104 points

51 Posts

Re: ContentPropertyAttribute in Silverlight?

I've got this to work before.  What I did is import the right namespaces, create a dependency property for the children collection "Collection(of Child)" and decorate the class with the ContentProperty attribute and point it to your collection property name.

Imports System.ComponentModel
Imports System.Windows.Markup

<ContentProperty("Children")> _
Public Class Parent

Public Shared ReadOnly ChildrenProperty As DependencyProperty = DependencyProperty.Register("Children", GetType(Collection(Of Child)), GetType(Parent), New PropertyMetadata(New Collection(Of Child)()))

Public Property Children() As Collection(Of Child)
Get
Return DirectCast(GetValue(Parent.ChildrenProperty), Collection(Of Child))
End Get
Set(ByVal value As Collection(Of Child))
SetValue(Parent.ChildrenProperty, 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.

bryant
bryant

Star

Star

9927 points

1,629 Posts

Silverlight MVP

Re: ContentPropertyAttribute in Silverlight?

Yes, the ContentPropertyAttribute now exists. It didn't back when this thread was active since that was the 1.1 days.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities