views:

132

answers:

2

In our Silverlight 2 project we have created an attached property to perform on-the-fly translation to text properties of various user controls. To achieve this, we hook the Loaded event of the FrameworkElement when the property is set. When the event fires, we take the existing text property value and perform some simple string substitutions on it, before replacing the property value with the translated text. However, this results in the control being rendered with the untranslated text, then the text is quickly replaced with the translated version.

Is there an alternate event we can hook that would fire before the control is rendered?

A: 

I'm not totally sure about this, but can you use the LayoutUpdated event? It will fire when the control is resized and such (you could take measures to ensure your code only executes once.)

I know it doesn't seem like the "right" event for this but unfortunately Silverlight kinda leaves you standing there holding it when it comes to events.

Josh Einstein
The trouble with this is that the LayoutUpdated event does not supply a value for sender, so I cannot determine which FrameworkElement had it's layout updated.
X-Cubed
A: 

I've changed my code so that it now performs the translation as soon as the setter for the attached property is called. There's no need to wait for the FrameworkElement to have finished loading, as I can change the Text property long before the element is rendered.

My initial thoughts on using the Loaded event were to reduce the startup time of the application by only translating the controls that were visible on the screen. As it turns out, I'm duplicating some of the work performed by the runtime, as the runtime won't call the property setter until it needs to anyway.

X-Cubed