Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, Properties using strings

Tags:

string

c#

wpf

C#, Visual studio 2010, Windows 7

When you set the image to WPF control image you can specifify the source to the image like this

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

But how do you do with strings, I have a number of strings resources, for example, strings.resx, strings.sv-Se.resx etc. and want to use this "string concept" when specify the text to a button.

What should I write in the properties (or the XAML file for the window) to retrive the strings?

I have tried

/MyTest;component/strings.File

me:strings.File

But nothing seems to work.

like image 374
Stefan Olsson Avatar asked Feb 13 '26 20:02

Stefan Olsson


1 Answers

set the access specifier of resx file be 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 : Accessing strings from resx file

like image 173
Shebin Avatar answered Feb 15 '26 09:02

Shebin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!