Beware the decimal separator

code, silverlight — Szili @ 3:18 pm

The clash between decimal separators, double values and application culture already made Point type a victim. Today I found abound another one..

I had an iframe positioned above my silverlight control. Its dimensions was controlled from C# managed code (with the use of System.Windows.Browser library).
Or at least it should have been.

ERROR:

No matter I gave the right double values to set the iframe’s width, it just didn’t changed:

Iframe.SetStyleAttribute("width", value.ToString() + "px");

SOLUTION:

After a few rounds of debugging I found the solution. The problem was caused by the decimal separator being a comma instead of a point.

The fix is the same as with the Point type:

Iframe.SetStyleAttribute("width", value.ToString(System.Globalization.CultureInfo.InvariantCulture) + “px”);

Fear Blend 2 and keep your Xaml dry

code, silverlight — Szili @ 10:15 am

Okay, I like Blend 2, but it has its tricks..

A control’s xaml when was loaded in its constructor threw a Catastrophic failure.

I designed the control in Blend 2 without touching the xaml’s source. It was a pretty simple graphic, four rectangles in a canvas.
All had unique names so the problem wasn’t related to namescopes.

To cut a long story short it occurred to me, that one rectangle had three spaces after the value in its height property. Fixing this solved the problem.

The full Exception info after the jump.

(more…)

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 Szili | powered by WordPress with Barecity