Page view counter
ContentPropertyAttribute in Silverlight? Subscribe to this thread
Last post 12-03-2008 5:56 PM by bryant. 5 replies.
Sort Posts:
05-08-2007 3:50 PM
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>

 

psih128

Loading...
Joined on 05-08-2007
Posts 6
05-08-2007 8:27 PM
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"


Mark Rideout

Loading...
Joined on 01-03-2006
Redmond, WA
Posts 268
05-11-2007 3:30 PM
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?

psih128

Loading...
Joined on 05-08-2007
Posts 6
05-11-2007 4:48 PM
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.

bryant

Loading...
Joined on 10-22-2002
Simi Valley, CA
Posts 1,153
12-03-2008 5:37 PM
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 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
12-03-2008 5:56 PM
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.

bryant

Loading...
Joined on 10-22-2002
Simi Valley, CA
Posts 1,153
Microsoft Communities