Pixata Custom Controls
For Lightswitch

Recent Posts

Popular tags (# posts in brackets)

Anonymous types (3) ASP.NET (5) C# (3) C# tricks and tips (2) Computers (6) Design patterns (3) DomainDataSource (3) Dynamic data (4) Entity framework (3) Entity model framework (5) F# (3) LightSwitch (12) Linq (6) Microsoft (2) MVP (2) MVVM (2) Project Euler (2) RIA services (5) Silverlight (2) SQL Server (4) Unit testing (4) Visual Studio (7) WCF (3) WPF (3)

Gratuitous link to StackExchange




The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Actually, as I'm self-employed, I guess that means that any views I expressed here aren't my own. That's confusing!


Theme modified from one by Tom Watts
C#/F# code styling by Manoli (for posts pre-2016) and Google code prettify (for post from Jan 2016 and beyond)

My rambling thoughts on exploring the .NET framework and related technologies

The Stylable Label control Stylable Label, The Stylable Static Label control Stylable Static Label and The Stylable TextBox control Stylable TextBox

The Stylable Label and Stylable Static Label

Lightswitch allows you to choose one of a few predefined text styles when you display text on the screen. Sometimes you want to override these, and choose your own styles. These two controls allow you to do just that. They both work in the same way, with the only difference being that the Stylable Label binds to data on the screen (like most Lightswitch controls), whereas the Stylable Static Label is a static control that ignores the data to which it is bound, and takes its text from whatever you set in the screen designer.

To use the controls, add one to the screen, and set the properties as desired. The Alignment, Font Size, Font Colour, Bold, Italic and Background Colour properties all apply to the text itself, and are self-explanatory. The border and drop shadow properties are the same as explained on the Static Image Viewer control page.

If you are using the Stylable Static Label, then there is also the Text property, which specifies what text is displayed on the screen.

The Stylable TextBox

This works in exactly the same way as the Stylable Label, except that being a TextBox, it allows editing of the text.

Due to a bug in Lightswitch v1 (reported by me, accepted by Microsoft and fixed in v2), setting the background colour of the TextBox doesn't make any difference to what is displayed on the screen, as Lightswitch overrides your setting. However, before v2 users breathe a sigh of relief, I should point out that the Cosmopolitan shell in v2 seems to do the same thing! I haven't put too much effort into investigating this problem, as I'm not convinced of the value of this control anyway (see note below).

A note about these controls

Lightswitch takes a cue from the HTML/CSS paradigm on the web, and uses themes, rather than requiring you to set properties on every individual element. This allows you to switch themes, and have all elements of a type to display in a consistent manner. Using controls like the ones described on this page can break that consistency, and give you extra maintenance work when changing themes. For that reason, you should use them sparingly.

It's worth noting that these controls only exist because when I first had a go at creating my own controls, the standard Control template in the Lightswitch Extensibility Toolkit included a TextBox. As I was only playing around, I didn't bother changing this, and used it for testing. The result of this was the Stylable Textbox. With a simple change of the base control from TextBox to TextBlock, I had the Stylable Label, and with the addition of a designer property bound to the Text property of the TextBlock, I had the Stylable Static Label.

At that stage, I was ready to create some real controls, but decided to leave these three in as it was too much work to remove all the files they used! I rarely use them, and recommend you do the same. The Stylable Static Label is useful for headings on a home screen, but even then, only with care. If you want to provide styled text, I generally recommend you use Yann Duran's TextBlock control (part of his Luminous Controls extension), as this will adapt to the current theme.