WPF:如何将字符串绑定到标签内容的动态资源

发布于 2025-01-25 03:45:42 字数 474 浏览 2 评论 0原文

我是WPF和MVVM的新手。我在WPF应用程序中具有动态语言更改功能。对于此功能,我为每种语言都有2个资源词典。在UI中的语言更改中,我将为应用程序添加并删除相应的资源。 这样,在给定时间点,只有一个资源词典在应用程序资源中可用。

由于所有字符串都是动态资源,因此我现在需要如何将字符串添加到XAML中的动态资源字符串中。

对于ex:我想要下面的

 <Label FontWeight="Medium" Content="{DynamicResouce Name} + myText"/>

“名称”之类的东西,是两个资源词典中可用的键,如下所示。

<system:String x:Key="Name">Name</system:String>

现在,需要知道如何将“ myText”连接到标签内容中的名称(DynamicResource)。

I am new to WPf and MVVM. I have Dynamic language change functionality in my wpf application. For this functionality I have 2 Resource dictionary for each language.On Language change in UI, I am adding and removing the corresponding ResourceDictionary to the application.
With this, at a given point of time only one Resource Dictionary is available in Application resource.

As all strings are Dynamic resource, I need to now how to add a string to a dynamic resource string in xaml.

For ex: I want something like below

 <Label FontWeight="Medium" Content="{DynamicResouce Name} + myText"/>

Here "Name" is a Key available in both resource dictionary as shown below.

<system:String x:Key="Name">Name</system:String>

Now, need to know how to attach "myText" to the Name(DynamicResource) in the Label Content.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再让梦枯萎 2025-02-01 03:45:42

您只需在Label中只需使用textBlock

<Label>
   <TextBlock>
      <Run Text="Text1"/>
      <Run Text="Text2"/>
   </TextBlock>
</Label>

You can just simply use TextBlock inside the Label

<Label>
   <TextBlock>
      <Run Text="Text1"/>
      <Run Text="Text2"/>
   </TextBlock>
</Label>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文