【问题标题】:C#, Properties using stringsC#,使用字符串的属性
【发布时间】:2011-08-10 07:01:58
【问题描述】:

C#、Visual Studio 2010、Windows 7

当您将图像设置为 WPF 控制图像时,您可以像这样指定图像的来源

/MyTest;component/images/Misc/bg.jpg

但是你如何处理字符串,我有一些字符串资源,例如, strings.resx、strings.sv-Se.resx 等,并且想在什么时候使用这个“字符串概念” 为按钮指定文本。

我应该在属性(或窗口的 XAML 文件)中写入什么来检索字符串?

我试过了

/MyTest;component/strings.File

我:strings.File

但似乎没有任何效果。

【问题讨论】:

  • 取决于您想要实现的目标(本地化?),this 可能是您正在寻找的,或者这个问题甚至是重复的。

标签: c# wpf string


【解决方案1】:

设置resx文件的访问说明符为public

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prop="clr-namespace:WpfApplication1.Properties"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox Text="{x:Static prop:Resources.String1}"/>


    </Grid>
</Window>

refrence : 从resx file 访问字符串

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-12-12
  • 1970-01-01
  • 2015-09-29
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 1970-01-01
相关资源
最近更新 更多