views:

38

answers:

2

I have a method Translate extension which searches for a translation. Normally translations are loaded in Window constructor (I tried in App.Setup too). No if i run the application all the translations are displayed correctly, but when opening a user control all translations are gone.

So the question is where do I put my initialization code so it would be executed before VS initializes design window

+1  A: 

it should be default constructor

idursun
Can I have one common place for that. I have a lot of controls and one thing is that this is a lot of copy/pasting. Another thing is that when I compile program I will run initialization every time control is created. Do you know of any other solution?
Sergej Andrejev
I think it all depends on what and how your code is searching translation extensions. I would probably encapsulate translation search logic into a static class and initialize only once.
idursun
A: 

Either the class constructor (or code called from it) or some static member initialized by a static constructor.

Option 1:

public partial class MyUserControl : UserControl
{
    int thisWillWork = 1;
    int thisWillAlsoWork;

    public MyUserControl()
    {
        thisWillAlsoWork = 1;

        InitializeComponents();
    }

Option 2:

public class SomeOtherClass
{
    public static int YouCanUseThis = 1;
    public static int AndThisAlso;

    static SomeOtherClass()
    {
        AndThisAlso = 1;
    }
}
Nir