【问题标题】:How to use a nested string in App.xaml static resources...?如何在 App.xaml 静态资源中使用嵌套字符串...?
【发布时间】:2020-09-19 20:10:23
【问题描述】:

在我的 App.xaml 文件中,我定义了以下静态资源...

<x:String x:Key="StaticString1">static string 1</x:String>
<x:String x:Key="StaticString2">static string 2 using {StaticResource StaticString1}</x:String>

在内容视图中(在另一个页面上),我想显示StaticString2 并让它自动拉入StaticString1,但它不起作用。 我希望它说“使用静态字符串 1 的静态字符串 2”,但它只显示带有花括号的文字(“使用 {StaticResource StaticString1} 的静态字符串 2”)。

是否可以在静态资源中执行此操作,或者我需要使用 &lt;Label.FormattedText&gt;&lt;Span&gt;s 吗?

【问题讨论】:

    标签: xaml xamarin xamarin.forms staticresource app.xaml


    【解决方案1】:

    不,我认为您不能在 xaml 中组合两个字符串。

    您可以使用&lt;Label.FormattedText&gt;&lt;Span&gt; 来实现此目的:

        <ContentPage.Content>
    
            <StackLayout>
                <Label >
                    <Label.FormattedText>
                        <FormattedString>
                            <Span TextColor="Black" FontSize="18" Text="{StaticResource StaticString2}"/>
                            <Span TextColor="Black" FontSize="18" Text=" "/>
                            <Span TextColor="Black" FontSize="18" Text="{StaticResource StaticString1}"/>
                        </FormattedString>
                    </Label.FormattedText>
                </Label>
            </StackLayout>
            
        </ContentPage.Content>
    

    App.xaml:

        <x:String x:Key="StaticString1">static string 1</x:String>
        <x:String x:Key="StaticString2">static string 2 using </x:String>
        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多