What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 23432 |  Welcome, Guest!   Register  Login
Home > Articles > Silverlight > Silverlight Controls Part -3

Silverlight Controls Part -3

Article posted by SheoNarayan on 12/9/2011 | Views: 2348 | Category: Silverlight | Level: Beginner | Points: 250 red flag


In this article, we are going to explore the Silverlight controls like TextBox,PasswordBox, RichTextBox and their related properties.

This article is the continuation of my last article in Silverlight controls series, read last article here.

TextBox

TextBox control is used to get input data from the user in Silverlight.

Get 500+ ASP.NET web development Tips & Tricks and ASP.NET Online training here.

Text

In case we want to specify its value, we specify the "Text" property.

<TextBlock Canvas.Top="15" Canvas.Left="5" Text="Your name : "/>

<TextBox x:Name="TextBoxName" Height="25" Width="100" Canvas.Left="100" Canvas.Top="10"/>

TextWrapping, AcceptReturn

In case we want to display a multi-line textbox so that user can be able to submit large amount of textual data, we can set the height and width properties of the textbox along with TextWrapping to wrap and AcceptReturn to true value. This can be said to be a good thing as one control perfors the role of textbox as well as the teatarea.

TextWrapping allows the text to automatically wrap to the next line in case use keeps writing more content in a single line.

AcceptReturn allows user to press enter key to shift the cursor to next line in the textbox.

<TextBlock Canvas.Top="45" Canvas.Left="5" Text="Your details : "/>

<TextBox x:Name="TextBoxDetails" Height="150" Width="250" Canvas.Left="100" Canvas.Top="45" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" AcceptsReturn="True" />

Output

PasswordBox

PasswordBox allows us to provide a password box to the user that enables user to submit password. In this textbox, the characters that are entered, appears as masked.

Password

In case we want to prepopulate the password to the Password box, we can set the Password attribute.

PasswordChar

In case we want a custom character as the masked character for the Password box, we can set to PasswordChar attribute.

<PasswordBox x:Name="PasswordBox1" Width="160" Height="35" Canvas.Left="20" Canvas.Top="20" BorderThickness="5" Password="MyPassword" PasswordChar="#" /> 

Output

RichTextBox

RichTextBox control allows us to display and edit rich content into Silverlight application. Rich content can include bold, italic, different size text or image.

RichTextControl allows several child controls to format the text in italic, bold and color, it also provide child control to insert image in the RichTextBox control.

Paragraph

A mandatory tag inside the RichTextBox control to place any content.

Italic

Used to format the text in Italic style

Bold

Used to format the text in bold style

Span

Used to format the inline text in the RichTextBox control.

InlineUIContainer

A mandatory child element that is used to place Image in the RichTextBox control.

Image

Image is used to place the image in the RichTextBox control. Source attribute is used to specify the url of the image. In order to display the image, we need to

<RichTextBox Height="250" Width="250" x:Name="DescriptionBox" Canvas.Top="10" Canvas.Left="10">

<Paragraph>

This is the simple text.

<Italic>Itali

<Bold>cccc</Bold>

</Italic>

<LineBreak/>

<LineBreak/>

This

<Span FontFamily="Arial" FontSize="18">is a good boy.</Span>

<LineBreak/>

<LineBreak/>

<LineBreak/>

<LineBreak/>

<InlineUIContainer>

<Image Source="../Images/itfunda.jpg" Stretch="Uniform" Width="150" Height="100" />

</InlineUIContainer>

</Paragraph>

</RichTextBox>

Output

How to add content to the RichTextBox control dynamically from code behind?

If we want to add BOLD content, we can use Bold class like below.

Code

Response.Write(Date.ToShortDateString());

Bold b = new Bold();

b.Inlines.Add("This text is in bold");

Paragraph p = new Paragraph();

p.Inlines.Add(b);

DescriptionBox.Blocks.Add(p); 

Hope this article was useful. Thanks for reading, hope you liked it.

Keep reading my forth coming articles on Silverlight. To read my series of articles,click here.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Sheo Narayan

Experience:8 year(s)
Home page:http://www.snarayan.com
Member since:Tuesday, July 08, 2008
Level:HonoraryPlatinum
Status: [Microsoft_MVP] [Administrator]
Biography:Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001.

Connect me on Facebook | Twitter | LinkedIn | Blog

>> Write Response - Respond to this post and get points
Related Posts

Years ago I came across DeepZoom in a Microsoft Teched Conference that was held in South Africa in Durban. After the conference I wrote an article on the subject. But when it was released it was a wow technology but it was still lacking something. I waited for Silverlight 3 to be released and new DeepZoom came into the picture again, and I was so impressed with the product now. I have demonstrated this in the old article and I must say I wasn’t impressed as am now. In July 2009 DeepZoom was released and I was ready to try it again and I was not disappointed at all.

This article shows how you can bind to a property located in the data context of your parent which is not accessible to the data template item in silverlight, also as silverlight does not fully support 'relative source' is cannot be used.

In this post I teach you how can you add a computed property in WCF ria services

In this article I will not be binding the controls with the data from Database. My example is a very simple example, like a hello world type of Example. In this article I am going to bind the individual controls from a property value. To follow my example you need Expression Blend.

In my previous Articles we have learnt “How to start with Silverlight”. In the present article we will learn Silverlight Controls. I am covering the entire Article in a practical view so, I advise you please remind previous articles and create a test application for side-by-side practical or follow these steps to create a new test application:

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 11:27:07 PM