Skip to main content

Microsoft Silverlight

Create a control with a Children property?RSS Feed

(1)

JFo
JFo

Member

Member

4 points

5 Posts

Create a control with a Children property?

I have created a SampleControl, and successfully got a Text property to work, but when I want to branch out to add children to my control, I'm running into parser errors. 

public class SampleControl : Control {

private string _text;

public SampleControl() {

    System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("SilverlightProject1.SampleControl.xaml");

    this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());

}

 

public string Text {

    get { return _text; }

    set { _text = value; }

}

private VisualCollection _children;

public VisualCollection Children {

    get { return _children; }

    set { _children = value; }

}

}

 In Page.xaml I've tried various things

<Canvas x:Name="parentCanvas" xmlns="http://schemas.microsoft.com/client/2007"  xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Loaded="Page_Loaded"  x:Class="SilverlightProject1.Page;assembly=ClientBin/SilverlightProject1.dll"

xmlns:sample="clr-namespace:SilverlightProject1;assembly=ClientBin/silverlightProject1.dll"

Width="640" Height="480" Background="White" >

<sample:SampleControl>

    <sample:SampleControl.Children>

        <VisualCollection>

             <TextBlock>One</TextBlock>

         </VisualCollection>

    </sample:SampleControl.Children>

</sample:SampleControl>

</Canvas>

And I get

---------------------------
Microsoft Internet Explorer
---------------------------

Silverlight error message    
ErrorCode: 2254
ErrorType: ParserError      
Message: AG_E_PARSER_UNKNOWN_TYPE    
XamlFile: Page.xaml    
Line: 12    
Position: 35    

---------------------------
OK  
---------------------------

Where line 12 position 35 corresponds to <sample:SampleControl.Children>

forci
forci

Member

Member

351 points

275 Posts

Re: Create a control with a Children property?

When or if you get the answer, please post it here.

Make love not war.

luisabreu
luisabreu

Participant

Participant

1676 points

612 Posts

Re: Create a control with a Children property?

hello.

i believe that the parsing done on the current version is a bit limited. What i'm saying is that support for element property access is only supported for some elements (unlike wpf, where i think you can choose how your properties are represented in xaml).

nkramer
nkramer

Member

Member

14 points

7 Posts

Microsoft

Re: Create a control with a Children property?

You are correct, in Silverlight 1.1 the parser is extensible to a certain degree but not completely extensible, custom properties are okay as long as the property type is a built-in type and doesn't require a property element.  Our current thinking is we'll enable the children scenario in a future CTP.  Thanks.

-Nick Kramer
Silverlight program manager
http://blogs.msdn.com/nickkramer

JFo
JFo

Member

Member

4 points

5 Posts

Re: Create a control with a Children property?

I've posted the closest workaround I could find (for now):

http://jfoscoding.blogspot.com/2007/06/hacking-in-items-property.html

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities