【问题标题】:How to use same string resource for different item types如何为不同的项目类型使用相同的字符串资源
【发布时间】:2020-09-23 10:59:40
【问题描述】:

我有一个名为Products.Label 的字符串,用于AppBarButton。如何在不崩溃的情况下为TextBox 使用相同的字符串?

MainPage.xaml

...
<AppBarButton Name="AppBarButtonProducts" x:Uid="Products"/>
...

Settings.xaml

...
<TextBlock x:Uid="Products/Label" Style="{StaticResource HeaderTextBlockStyle}" />
...

【问题讨论】:

    标签: windows xaml uwp uwp-xaml


    【解决方案1】:

    如何为不同的项目类型使用相同的字符串资源

    您可以在应用程序资源中创建 x:string resource 以进行不同的控制,如下所示。

    <Application.Resources>
        <x:String x:Key="Placeholder">Placeholder Content</x:String>
    </Application.Resources>
    
    
    <TextBox
        Height="44"
        PlaceholderText="dddd"
        Text="{StaticResource Placeholder}"
        />
    

    【讨论】:

    • Placeholder Content需要添加到哪个文件?
    • 您可以将 x:string 添加到 App.xaml 文件中。
    • 但是如果我们想让这些字符串也被本地化呢?我们如何使用 x:uid 和 .resw 文件组合多种语言模式并同时在多个控件上使用它们?因为直到现在我总是需要在代码隐藏中做这件事......但我想尽可能多地在 XAML 中做。最好的问候,感谢您的关注。
    • 已经检查了这个document,它告诉了如何在 uwp 中本地化字符串。
    猜你喜欢
    • 2020-05-13
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2023-03-25
    • 2011-08-27
    • 1970-01-01
    相关资源
    最近更新 更多