Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am writing a multilanguage application. So each text for output (in C#-Code and in XAML too) has to be held in (Language-)ResourceDictionary. This works fine with plain text. E.g:

XML
<!-- The Dictionary for English language -->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib"
                    >
    <!-- Dialog 17-->
    <s:String x:Key="TextOfTbl7Key">This is the all plain text of TextBlock7 in English</s:String>
    ...
    ...
</ResourceDictionary>


XML
<!-- The application -->
<Window x:Class="MyAppl.Windows.Dialog17"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
         .....
         <TextBlock Text="{DynamicResource TextOfTbl7Key}"/>;
         ...
         ...
    </Grid>
</Window>


But what, if the TextBlock with text to extract contains formatted Text, i.e. the TextBlock has Inlines:

XML
<TextBlock Name="Tbl8">
   Normal stuff, something very <Bold>important</Bold>, and a <Italic>Name</Italic> of something. 
</TextBlock>


What I want is to export this as a single ... (whatever - but string does not work). No solution is to divide the text in many textparts (with own keys), because the composition of the text will depend on the language (And this solution would be ugly too). One solution could be to hold the entire TextBlock as a resource in the ResourceDictionary this way:

XML
<!-- The Dictionary for English language -->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib"
                    >
    <!-- Dialog 17-->
    <s:String x:Key="TextOfTbl7Key">This is boring text of TextBlock7 in English</s:String>
    <TextBlock x:Key="Tbl8Key">Normal stuff, something very <Bold>important</Bold>, and a <Italic>Name</Italic> of something </TextBlock>
    ...
    ...
</ResourceDictionary>




But I have no idea how to access the Resource-TextBlock as an Elemnet in XAML.

XML
<!-- The application -->
<Window x:Class="MyAppl.Windows.Dialog17"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
         .....
         <TextBlock Text="{DynamicResource TextOfTbl7Key}"/>;
         <!-- Here Tbl8 should be instantieted by access to ResourceDictionary --> 
         ...
         ...
    </Grid>
</Window>


Thanks for your answers in advance.
Posted
Updated 25-Feb-13 3:58am
v8

1 solution

maybe storing resources in .resx files will work better. Here is a simplest way to do that:
add localization via resx files. It works for sure for simple strings. The only thing I didn't check is whether escaped xml tags work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900