Sergej Andrejev
Sergej Andrejev

Reputation: 9403

Where should I put initialization code so it would be executed in before VS initializes my control in design mode

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

Upvotes: 0

Views: 343

Answers (2)

Nir
Nir

Reputation: 29584

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;
    }
}

Upvotes: 0

idursun
idursun

Reputation: 6335

it should be default constructor

Upvotes: 1

Related Questions