Archive for January, 2010

Quick way of checking if you’ve localised your Silverlight or WPF Xaml files

I typically use data binding to perform localisation of labels but I typically start out just by having plain text and go back later and replace these with bindings at a later stage.

e.g. <TextBlock Text=”{Binding Strings.Label_ContactDetails}” />

Here’s a really quick and easy way to make sure you’ve got your Xaml files completely localised.

1. Make sure you have downloaded LINQPad and installed it.

2. Start LINQPad and change the Language dropdown to C# Statement(s)

3. Paste this query into LINQPad and change the path to point to your project or solution folder

Code Snippet
  1. string path = @"C:\MyProjectFolder";
  2. XNamespace ns = ";;
  4. var attributes = new List<XName> { "Text", "Tag", "Content", "Header", "ToolTipService.ToolTip" };
  6. var files = System.IO.Directory.GetFiles(path, "*.xaml", System.IO.SearchOption.AllDirectories);
  7. var q = from eachFile in files
  8.         let fileContent = XElement.Load(eachFile)
  9.         from eachNode in fileContent.Descendants()
  10.         from eachAttribute in eachNode.Attributes()
  11.         where attributes.Contains(eachAttribute.Name)
  12.         where !eachAttribute.Value.StartsWith("{")
  13.         select new
  14.         {
  15.             Text = eachAttribute.Value,
  16.             Node = eachNode.Name.LocalName,
  17.             Attribute = eachAttribute.Name,
  18.             FileName = eachFile.Substring(path.Length)
  19.         };
  21. q.Dump();


4. Click Run and viola you have a list of all the nodes in all Xaml files that need localising!

Hope this helps!


Leave a comment

Spherical Glass Buttons in WPF and Silverlight

I long while back I post an article about Making a Glass Ball act like a Glass Button using Expression Blend and WPF. Well a reader asked me if I could share the code for these glass buttons so I’ve added a resource dictionary to my SkyDrive with the following Button templates:


Unfortunately this version is out of date, and I seem to have lost the original code which was more functionally complete, as you can see disabled buttons don’t fade, they used to turn to transparent glass buttons. Looking back on this my main criticism would be that the colour of the button is difficult to change, I’d have preferred if the background could be adjusted just by changing the BackColor property on a button but the gradients are just too complex to achieve this at the moment.

Hope this helps someone!

1 Comment