Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Aug 18, 2010 1:06 am Post subject: How do I localize XAML TextBlocks? |
|
|
Say you have an XAML TextBlock like:
Code: | <TextBlock>Some Text</TextBlock> |
When you scan the XAML with Globalizer the content of the text block is not picked up. If you look at the default WPF Options (when scanning) you will see there is no specific entry for TextBlocks. If you try to add a WPF Conversion rule for "TextBlock.Content" then the TextBlock content will be scanned - but you now have another problem. Globalizer will convert the element to something like:
Code: | <TextBlock>
<Resx ResxName="MyApp.Window1" Key="TextBlock_Content1" />
</TextBlock |
And when you try to open this in the designer you will get the following error:
Quote: | The property 'Inlines' is read-only and cannot be changed. |
The problem is that the TextBlock element does not support any child elements other than simple text - so you cannot localize the content like this. So instead of adding a conversion rule in Globalizer for "TextBlock.Content" you need to change your XAML to set the Text property (inside the TextBlock tag) like:
Code: | <TextBlock Text="Some Text" ></TextBlock> |
The default Globalizer WPF conversion rules (which scan the Text properties of all controls) will now scan and convert the element to something like:
Code: | <TextBlock Text="{Resx ResxName=MyApp.Window1, Key=TextBlock_Text1}" ></TextBlock> |
This will now load as expected in the designer. _________________ Infralution Support |
|