question

DeepNavadiya-4774 avatar image
0 Votes"
DeepNavadiya-4774 asked DeepNavadiya-4774 commented

How to handle localization in <RichTextBox><FlowDocument><Paragraph>?

I am using <RichTextBox><FlowDocument><Paragraph> to display the Terms and Condition of my application.

 <RichTextBox Margin="10">
                 <FlowDocument>
                     <Paragraph TextAlignment="Center" FontSize="12">SYSTEM</Paragraph>
                     <Paragraph Name="LoginParagrahp1" FontStyle="Normal" TextAlignment="Justify" FontSize="10" >
                         <Run Text="{l:Translate IDS_LOGIN_PARAGRAPH1}"></Run>
                     </Paragraph>
                 </FlowDocument>
 </RichTextBox>

but it gives me an exception on build.

The string is coming from the .resx file. How can I solve this issue?





windows-uwpwindows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered DeepNavadiya-4774 commented

I use the following steps and modify your code, it can run successfully.
1.Create a resource file under Properties of the WPF project and name it Translate.resx.
118961-1.png
2.Edit the Translate.resx file. And if you want to use XAML, you need to change the Access Modifier to public.
118915-2.png
3.Bind resource values to properties of WPF window:

 xmlns:l="clr-namespace:localizationFlowDocument.Properties"

4.XAML as follows:

 <Window x:Class="localizationFlowDocument.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:localizationFlowDocument"
         xmlns:l="clr-namespace:localizationFlowDocument.Properties"
         mc:Ignorable="d"
         Title="MainWindow" Height="450" Width="800">
     <Grid>
         <RichTextBox Margin="10">
             <FlowDocument>
                 <Paragraph TextAlignment="Center" FontSize="12">SYSTEM</Paragraph>
                 <Paragraph Name="LoginParagrahp1" FontStyle="Normal" TextAlignment="Justify" FontSize="10" >
                     <Run Text="{x:Static l:Translate.IDS_LOGIN_PARAGRAPH1}"></Run>
                 </Paragraph>
             </FlowDocument>
         </RichTextBox>
     </Grid>
 </Window>

The result is as follows:
118963-3.png





1.png (9.1 KiB)
2.png (9.3 KiB)
3.png (5.3 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I can not directly use the file name when I am Bind resource values to properties of the WPF window because My app is multi-language so it uses multiple .resx files.

This is what I am adding to my WPF window to Bind the resource values.


  xmlns:l="clr-namespace:NXGLocalizationService.Language;assembly=NXGLocalizationService"

Can you please provide a solution for that?

0 Votes 0 ·