Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:

<!-- 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>
 
<!-- 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:
 
<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:
 
<!-- 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.
 
<!-- 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 23-Feb-13 7:28am
Edited 25-Feb-13 3:58am
v8

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 CHill60 280
1 Sarvesh Kumar Gupta 238
2 Sergey Alexandrovich Kryukov 203
3 OriginalGriff 163
4 DamithSL 153


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid