views:

917

answers:

3

I need to bind labels or items in a toolstrip to variables in Design Mode. I don't use the buit-in resources not the settings, so the section Data is not useful. I am taking the values out from an XML that I map to a class.

I know there are many programs like: http://www.jollans.com/tiki/tiki-index.php?page=MultilangVsNetQuickTourForms but they work with compiled resx. I want to use not compiled XML.

I know that programatically i can do it, i create a method (for example, UpdateUI()), and there I assign the new values like this: this.tsBtn.Text=Class.Texts.tsBtnText;

I would like something i could do from Design Mode or a more optimized way than the current one. Is there any Custom Control out there or Extension?

A: 

Try with inheriting basic win controls and override OnPaint method. Example bellow is a button that has his text set on paint depending on value contained in his Tag property (let suppose that you will use Tag property to set the key that will be used to read matching resource). Then you can find some way to read all cache resource strings from xml files (e.g. fictional MyGlobalResources class.

public class LocalizedButton : Button
{
    protected override void OnPaint(PaintEventArgs pevent)
    {
        base.OnPaint(pevent);
        this.Text = MyGlobalResources.GetItem(this.Tag.ToString());
    }
}
Aleksandar
+1  A: 

Aleksandar's response is one way to accomplish this, but in the long run it's going to be very time consuming and won't really provide much benefit. The bigger question that should be asked is why do you not want to use the tools and features built-in to .NET and Visual Studio or at least use a commercial third-party tool? It sounds like you are spending (have spent?) a lot of time to solve a problem that has already been solved.

Scott Dorman
The problem is I want not programming people to have the ability to translate the texts I use from an XML. I put the XML in the web and they can pass it to the web with the translation directly, without the need to compile anything
netadictos
You could still use the built-in .NET features and just get a decent translator-friendly RESX editor, such as the open source <a href="http://sourceforge.net/projects/resx/">Resx Editor</a>.I haven't used it before, so can't vouch for quality or usefulness.
Kevin Thiart
sorry about the link: http://sourceforge.net/projects/resx/
Kevin Thiart
A: 

You can use satellite assemblies for localization and generate them using your XML file as a source for the translated entities. more about satellites http://msdn.microsoft.com/en-us/library/21a15yht(VS.71).aspx

sure it's not from design mode, but there's no way to do it this way with your restrictions.

alexm