wpf - 在 WPF 中串联静态资源

标签 wpf xaml

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

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

我该怎么做? 感谢您的帮助。

最佳答案

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

<Label Content="Smth"/>

转化为

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

您可以在 xaml 中添加 TextBlock 并显式分配来自 Resources 的两个字符串:

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

关于wpf - 在 WPF 中串联静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44086570/

相关文章:

c# - 将自定义控件内的 TextBlock 绑定(bind)到同一自定义控件的依赖属性

c# - 如何在 WPF 中与 Width ="150*"相反?

wpf - 使用XAML将DatePicker设置为Today

c# - WPF 选择 TreeView 项目作为上下文菜单称为

wpf - ListView中的垂直网格线

.net - .NET 的 UI 使用统计收集库

WPF:指针下的颜色

c# - 设置 Window.Content 不会破坏之前存在的 UI?

c# - 在共享 (.shproj) 项目中添加引用

c# - 值不能为空。参数名称 : key (only happens on XAML Designer's design view)