WPF在元素标记

时间:2017-12-01 10:59:40

标签: c# wpf xaml multilingual resourcestring

我正致力于创建支持多语言的WPF应用程序。所以,我把所有的"翻译成#34;字符串到字符串资源。

我知道如何使用XAML中的这些资源,但我在 打开和关闭标记 中使用它时遇到了麻烦。

例如:

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

正如您所见,Click hereto reset your password!位于元素标记内。我的问题是,如何从字符串资源中检索Click hereto reset your password!

这是我的字符串资源。

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

感谢您的帮助......

1 个答案:

答案 0 :(得分:3)

也许我看这个太简单了,但这样的事情就足够了吗?

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