Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 605 |  Welcome, Guest!   Register  Login
Home > Articles > Silverlight > Silverlight Controls Part -3

Silverlight Controls Part -3

Article posted by SheoNarayan on 12/9/2011 | Views: 1392 | 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

In this article, I will demonstrate you guys how to animate the items in a specific direction in PathListBox control. This not only guide you for animation in PathListBox but also will help you understanding the StoryBoard creation (if you are very new to Silverlight). Read the whole article and at the end don’t forget to leave your comments.

In most of my career, I worked with these kinds of Systems. How track someone? How to intercept Phone calls, How to Spy on Someone? How to Sniff on Devices? The things you see on TV, some of them are not true and some are true and possible. Before you even try to do something illegal on the internet, you must know that there are people who might be looking at you with basic intelligence systems like the one I mentioned or the one I will present to you now. As you know you can just get the IP address of your client with just one line of code in c# and in this article I will show you how to use it to get their location and possibly more.

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:

In this article, we are going to learn the Binding of the Data in SilverLight by hard coding in XAML file as well as programmatically from the code behind.

From my last article on Silverlight we have seen that the Silverlight is meant for both Developer and Designers at bit differently from each-other. A Developer needs following: • Set up an IDE • An Editor to create an XAML and managed code • Moreover, SDK A designer needs to install some designer tools and a development environment which work with XAML

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 found 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/27/2012 7:40:00 PM