C#,使用字符串的属性

时间:2011-08-10 07:01:59

标签: c# wpf string

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

但似乎没有任何效果。

1 个答案:

答案 0 :(得分:2)

将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>

参考:从resx file

访问字符串