WPF use string resources in XAML within element tag

2.1k views Asked by At

I am working on creating WPF application that is multi language ready. So, I put all of "translatable" string into string resources.

I know how to use this resources from XAML, but I am having trouble to use it within the open and close tag.

For example:

<TextBlock FontSize="16" Padding="2, 5, 0, 0">
    <Hyperlink NavigateUri="www.blabla.com/forgotpassword" RequestNavigate="Hyperlink_RequestNavigate">Click here</Hyperlink>
    to reset your password!
</TextBlock>

As you can see Click here and to reset your password! are within element tag. My question is, how to retrieve Click here and to reset your password! from the string resources?

Here is my string resource.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:XRManager.Resources"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">

    <system:String x:Key="Click_Here">Click here</system:String>
    <system:String x:Key="Click_Here_Part_Reset_Password">to reset your password!</system:String>    

</ResourceDictionary>

Thanks for any help...

1

There are 1 answers

1
Jack On BEST ANSWER

Perhaps I'm looking at this too simple, but would something like this suffice?

<TextBlock FontSize="16" Padding="2, 5, 0, 0">
    <Hyperlink NavigateUri="www.blabla.com/forgotpassword" RequestNavigate="Hyperlink_RequestNavigate">
        <TextBlock Text="{StaticResource Click_Here}"/>
    </Hyperlink>
    <TextBlock Text="{StaticResource Click_Here_Part_Reset_Password}"/>
</TextBlock>