Is it possible to bind to resources that live in Resources.resx for the application in XAML
hi everybody
i am getting following problem,please help
Is it possible to bind to resources that live in Resources.resx for the application in XAML? I tried the following:
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prop="clr-namespace:TheNorthFace.Kiosk.Properties" />
<TextBlock Text={x:Static, prop:Resources.Label_1} />
</Grid>
where "Label_1" is the name of an Application resource in Resources.resx. The exception I got was :
{"Only public classes can be used in markup. 'Resources' type is not public."}
Is there a different way to do this? I couldn't find the answer in the SDK. It would seem to me to be a big limitation to not be able to use application resources in XAML, but I'm probably just missing something...
?How to bind to Application Resources in XAML?
[2431 byte] By [
chepodu] at [2008-2-14]
In my main application constructor I experimented with something that actually worked, but Cider didn't get it though. But if you are just hacking XAML this will work.
Take your Resource-object and do something like this:
// Get all properties from resx resource object
Type resType = typeof( Xyz.Xyz.Properties.Resources );
PropertyInfo[] properties = resType.GetProperties( BindingFlags.Static | BindingFlags.NonPublic );
then do
// Add properties to XAML Application.Resources
foreach( PropertyInfo property in properties )
{
//
if( property.PropertyType == typeof( string ) )
Resources.Add( property.Name, property.GetValue( null, null ) );
}
Then in your XAML code simply do:
<TextBlock><StaticResource ResourceKey="theResNameFromYourResX" /></TextBlock>
I wrote this code now from memory, so there might be some mistakes in it, but you get the concept: Enumerate the resource properties and add them to the XAML application resources.
hi malmer
Thanks for posting
and i have more information.
is it possible to run static values through a converter? i.e.:
<TextBlock Text={x:Static, prop:Resources.Label_1, Converter=ToUpperConverter}} />
or does that only work with databinding?
Converters in a non-databinding scenario.
please help me in that as soon as possible...
Thanks..
I have just finished the development of a
free tool that I call
ResEx, composite, translation friendly
resource editor for .NET.
It is a
free tool and I intend to keep it free, containing all current features. A small charge may be applied for some features I may introduce later, just to help me keep supporting and enhancing the project.
I encourage you to download ResEx and post any suggestions to the discussions page you can find under Help menu of the application.
Info and downloadHere is a list of
features provided by ResEx:
21- Translate values side by side (just like the old time classic VB6 resource editor)
- Lock specific strings so that translator does not translate them
- Ensure correct translation of strings with placeholders {0} {1} ...
- View resource strings in tree form
- Translate resources without Visual Studio IDE
- Search inside resource files while translating
Regards