Accessing contents of R.string using a variable to represent the resource name

You can use the method to convert string into int identifier: public static int getStringIdentifier(Context context, String name) { return context.getResources().getIdentifier(name, “string”, context.getPackageName()); } Pass in an activity as context parameter (or any other Context instance). Then you can use the identifier as usual with getString() method. Note that conversion from string to identifier uses … Read more

How to point one resource (a SolidColorBrush) at another

I agree with what Rachel said, but if you have to base it on an existing SolidColorBrush, you can do it with the following: <SolidColorBrush x:Key=”MyDataGridHeaderBrush” Color=”{Binding Source={StaticResource HeaderBrushDefinedElsewhere}, Path=Color}”/> Note this just works for the “Color” attribute, you’d have to do it separately for each attribute you needed.

Specify width/height as resource in WPF

Sure. <Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:sys=”clr-namespace:System;assembly=mscorlib” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <Page.Resources> <sys:Double x:Key=”Height”>200</sys:Double> <sys:Double x:Key=”Width”>200</sys:Double> </Page.Resources> <Grid> <Rectangle Height=”{StaticResource Height}” Width=”{StaticResource Width}” Fill=”Blue”/> </Grid> </Page>

Implicit styles in Application.Resources vs Window.Resources?

This is really the only special handling added to WPF and it was done by design. The code that implements it can be found in FrameworkElement, in the method FindImplicitStyleResource, which effectively does: internal static object FindImplicitStyleResource(FrameworkElement fe, object resourceKey, out object source) { // … DependencyObject boundaryElement = null; if (!(fe is Control)) boundaryElement … Read more

no resource found that matches the given name

Did you check to ensure that you have the string resource defined in res/values/strings.xml? <string name=”app_name”>”My App”</string> Sometimes, I’ve noticed eclipse will also throw errors that are hard to track if you have any .xml files with errors. I don’t think the parser recovers well and sometimes the errors you get can be misleading.

How do I read from a version resource in Visual C++

This is an edited version of my original answer. bool GetProductAndVersion(CStringA & strProductName, CStringA & strProductVersion) { // get the filename of the executable containing the version resource TCHAR szFilename[MAX_PATH + 1] = {0}; if (GetModuleFileName(NULL, szFilename, MAX_PATH) == 0) { TRACE(“GetModuleFileName failed with error %d\n”, GetLastError()); return false; } // allocate a block of … Read more

How to correctly get image from ‘Resources’ folder in NetBeans

This was a pain, using netBeans IDE 7.2. You need to remember that Netbeans cleans up the Build folder whenever you rebuild, so Add a resource folder to the src folder: (project) src project package folder (contains .java files) resources (whatever name you want) images (optional subfolders) After the clean/build this structure is propogated into … Read more