locked
How to create a Label on the fly? RRS feed

  • Question

  • I'm trying this:

    Label

     

     

    newlabel = new Label();
    newlabel.Content =
    "Hello World.";
    newlabel.Parent = StkPnl;
    //StkPnl.Controls.Add(newlabel);

    ...but "Parent" is readonly, and there is no "Controls" property for StkPnl (a StackPanel)


    Writer / Photographer: www.lulu.com/blackbirdcraven, www.bclayshannon.photoshop.com
    Friday, February 5, 2010 7:48 PM

Answers

  • You just add it to the StackPanel, using Children - don't worry about setting Parent:

    Label newlabel = new Label();
    newlabel.Content = "Hello World.";
    StkPnl.Children.Add(newlabel);

    Also: For code formatting, use the little </> icon in the upper right - it does a better job than pasting, and avoids the weird separations.

    Reed Copsey, Jr. - http://reedcopsey.com
    Friday, February 5, 2010 7:53 PM

All replies

  • Why "Label" is at the top of Mount Everest, and the rest of my code is in the Mariana Trench, I don't know. When I pasted it in, they were like peas in a pod.
    Writer / Photographer: www.lulu.com/blackbirdcraven, www.bclayshannon.photoshop.com
    Friday, February 5, 2010 7:49 PM
  • You just add it to the StackPanel, using Children - don't worry about setting Parent:

    Label newlabel = new Label();
    newlabel.Content = "Hello World.";
    StkPnl.Children.Add(newlabel);

    Also: For code formatting, use the little </> icon in the upper right - it does a better job than pasting, and avoids the weird separations.

    Reed Copsey, Jr. - http://reedcopsey.com
    Friday, February 5, 2010 7:53 PM