Posts Tagged ‘Silverlight’

Silverlight Styling

Tuesday, July 14th, 2009

Changing the styling of the Silverlight controls is simple. It’s somewhat similar to CSS, but it’s more robust and syntax is completely different. What is different in Silverlight and WPF is that you can completely re-define control’s UI and behavior using styles. It took me about 20 minutes from absolute zero to the “Aha!” moment and become an expert in styling WPF and Silverlight applications. Here are the 3 links that helped me to clear the mistery behind Silverlight styles:

1.       Using Style Elements to Better Encapsulate Look and Feel – a good example of how to change control’s properties using styles

2.       Using Control Templates to Customize a Control’s Look and Feel – a step further that shows how to make control look anyway you want. In other words how to draw control’s UI from scratch or combine several controls into one. All using styles! Pretty amazing yet simple.

3.       MSDN: Customizing the Appearance of an Existing Control by Using a ControlTemplate – the final piece of puzzle is about how to make control to react on events like Pressed or Disabled and change its appearance. Just few more words about this. Basically every control has a list of pre-defined events (they called states in Silverlight) which can be referenced by ControlTemplate. The list of states differs for each control. This information is available in MSDN on control’s Class page as a list of TemplateVisualStateAttribute attributes applied to the class.

-=Oleg=-

How to deploy Silverlight application to a Server

Thursday, June 18th, 2009

In two words: 1) copy your *.xap files; 2) make sure .xap and .xaml MIME types are registered.

Here is more information about registering mime types for Silverlight application.

Warning, if you are deploying your Silverlight application to a Virtual Folder of the existing website, then most likely you need to copy your ClientBin folder to the root of the website, not virtual folder.

-=Oleg=-

Silverlight Password Textbox

Wednesday, June 17th, 2009

Silverlight Textbox is not the same as ASP.NET.  There is no TextMode property that can be set to “password”.

Silverlight has a special control for Password fields. It’s called PasswordBox

Here is the sample of XAML with PasswordBox:

<PasswordBox Password="HelloWorld" x:Name="pbPassword">

 Another surprise from Silverlight development team is that PasswordBox control doesn’t have Text property. In order to retrieve the value of the Password field use the Password property instead:

string sPassword  = tbPassword.Password;

Recently I had to work on a prototype where TextBox control was originally used for collecting password information. So, I went and replaced TextBox control with Password control and then changing Text property to Password. Guess what, my code compiled fine but when I tried to run it, it crashed. The reason was in Style property.

<PasswordBox Password="HelloWorld" x:Name="pbPassword"
Style="{StaticResource myTextBoxStyle}" >

This style was defined for the TextBox. This style is not compatible with PasswordBox control. I didn’t have a chance to look at what exactly in myTextBoxStyle style is causing problems. I will find it out and update this post.

One more note about PasswordBox is that it has PasswordChar property which can be used to specify the masking character. It’s a nice useless feature with no real value. It would be much nicer if PasswordBox was inherited from TextBox so developers won’t spend their valuable time building special cases around this control.

Oleg.