在 WPF 中连接静态资源 [英] Concatenate StaticResources in WPF

查看:30
本文介绍了在 WPF 中连接静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将字符串资源中的两个字符串连接成一个标签.我想要这样的东西

I need to concatenate two strings from string resources into a label. I want something like this

<Label Content="{StaticResource Menu + " " + Name}"></Label>

我该怎么做?任何帮助表示赞赏.

How can I do that? Any help is appreciated.

推荐答案

当 Content 是 string 时,框架会在幕后创建一个 TextBlock 来显示它.所以

when Content is a string, framework creates a TextBlock behind the scenes to display it. So

<Label Content="Smth"/>

转化为

<Label>
    <TextBlock Text="Smth"/>
</Label>

您可以在 xaml 中添加 TextBlock 并从资源中显式分配两个字符串:

you can add TextBlock in xaml and explicitly assign two strings from Resources:

<Label>
    <TextBlock>
        <Run Text="{StaticResource Menu}"/>
        <Run Text="{StaticResource Name}"/>
    </TextBlock>
</Label>

这篇关于在 WPF 中连接静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆