Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How to create a control with string as direct content? RSS

20 replies

Last post Sep 25, 2008 02:27 AM by Todd Herman

(0)
  • sladapter

    sladapter

    All-Star

    43607 Points

    7907 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 22, 2008 09:40 PM | LINK

     He wants to put the content as string in between the control's beginTag and EndTag.  But in Silverlight that's not valid XAML:

    You can do this:

    <Button Content="Button"/>

    or this:

    <Button><TextBlock Text="Button"/></Button>

    But you can not do this:

      <Button>Button<Button>

     

    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • Harlequin

    Harlequin

    Member

    218 Points

    159 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 22, 2008 10:05 PM | LINK

    If I can't put a direct string in, which I now understand, why doesn't this work:

    <local:LinkLabel>
          <local:LinkLabel.Text>
                 test
          </local:LinkLabel.Text>
    </local:LinkLabel>

    When the attribute works:
    <local:LinkLabel Text="test" />

    Are they not the same?

  • Todd Herman

    Todd Herman

    Member

    626 Points

    126 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 22, 2008 10:14 PM | LINK

    No,  Just ignore that you are using Silverlight and think of the basics of XML.  In your first example, LinkLabel.Text is an element and you are trying to set the innter text to "test".  In the second one, you are setting the value of the "Text" attribute to "test".  The parser must treat these completely differently.

     Todd

    If this post answered your question, please mark as answered.

    Todd Herman
    http://blogs.thecodearchitects.com
  • Harlequin

    Harlequin

    Member

    218 Points

    159 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 22, 2008 10:58 PM | LINK

    But it takes this instead of Width="150":
    <local:LinkLabel>
       <local:LinkLabel.Width>
          150                                     <-- this works, sets the width of control to 150
       </local:LinkLabel.Width>
    </local:LinkLabel>

    So I guess I'm missing something in making a custom element do the same.

  • Todd Herman

    Todd Herman

    Member

    626 Points

    126 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 22, 2008 11:07 PM | LINK

    Good point.  I have never used Width in that manner.  I will play with it a little and see if I can come up with something.

     Todd

    If this post answered your question, please mark as answered.

    Todd Herman
    http://blogs.thecodearchitects.com
  • Harlequin

    Harlequin

    Member

    218 Points

    159 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 24, 2008 03:27 PM | LINK

    Just in case someone Googles this thread.

    Just found out that ContentProperty is bugged. So chalk it up as another "fixed in RTM".

    They REALLY need to have a Silverlight bug list and fix list or something. I've seen people in here spend DAYS on something, just to find out it's a Beta 2 bug. Ditto with this thing.

  • Todd Herman

    Todd Herman

    Member

    626 Points

    126 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 24, 2008 03:51 PM | LINK

    Harlequin

    So chalk it up as another "fixed in RTM".

     If you can send me a short project that tests what you are trying to accomplish I can test it for you to ensure it has been fixed in RTM.

     

    If this post answered your question, please mark as answered.

    Todd Herman
    http://blogs.thecodearchitects.com
  • sladapter

    sladapter

    All-Star

    43607 Points

    7907 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 24, 2008 04:02 PM | LINK

    You could test this simple Xaml, currently this is invalid even Button has Content property:

    <Button>Test</Button>

     

    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • Harlequin

    Harlequin

    Member

    218 Points

    159 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 24, 2008 04:39 PM | LINK

    Hey Todd. The link to the project is at the very bottom of the first post. In the project it sets the Text field in C#, but I needed it to be in Xaml for ease of use. Thus trying to shove text directly into the controls Xaml insides, or via a .Text element inside said control.

  • Todd Herman

    Todd Herman

    Member

    626 Points

    126 Posts

    Re: Re: How to create a control with string as direct content?

    Sep 24, 2008 05:10 PM | LINK

    Doh!  Sorry about that.  I see the link now.  I will check it out as soon as I get home this afternoon.

     

    If this post answered your question, please mark as answered.

    Todd Herman
    http://blogs.thecodearchitects.com