Product Spotlight
(0 votes)

Tip: There is no Label control in Silverlight, what should I use instead?

2 comments   /   posted by Denislav Savkov on Sep 04, 2008

Yes, that is right, there is no Label control in Silverlight. Instead you should use the new control System.Windows.Controls.TextBlock. Keep in mind that it can display only text, no images or other type of content, just text.

Xaml

<TextBlock x:Name="statusText" Text="Active" TextWrapping="Wrap" TextAlignment="Left" VerticalAlignment="Center"/>

C#

TextBlock statusText = new TextBlock();
statusText.Text = "Active";
statusText.TextWrapping = TextWrapping.Wrap;
statusText.TextAlignment = TextAlignment.Left;
statusText.VerticalAlignment = VerticalAlignment.Center;

That's it!

 

Filed under: Controls and UI


Comments

Comments RSS RSS
  • RE: Tip: There is no Label control in Silverlight, what should I use instead?  

    posted by anon on Nov 07, 2008 16:46

    how is this a label??

    isnt this just a textblock with the word Active??

  • RE: Tip: There is no Label control in Silverlight, what should I use instead?  

    posted by iiordanov on Nov 10, 2008 02:09

    Hi anon,

    Yes this is just a textblock with the word Active in it, but there is no other control that is closer to the standard label control.
    However the release of the Silverlight Control Toolkit contains control named Label and it can be used instead of the TextBlock. You can find more information about the Silverlight Control Toolkit here.

Add Comment