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

Deep Navadiya 1 Reputation point
2021-07-28T17:30:31.233+00:00

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?

Universal Windows Platform (UWP)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,778 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,541 Reputation points Microsoft Vendor
    2021-07-29T06:03:47.817+00:00

    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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.