When I load solution and there is an opened designer tab for some window, then this window static constructor is not executed.
Perhaps my conclusion is wrong (because I am absolutely clueless how designer load things), but here is a test case:
Create new WPF project.
Create simple extension
public class MyExtension : MarkupExtension
{
public static bool Test;
public override object ProvideValue(IServiceProvider serviceProvider) => Test.ToString();
}
- Add to main window
<TextBlock Text="{local:My}" />
and
static MainWindow()
{
MyExtension.Test = true;
}
- Now compile it (F6),
TextBlock
should showTrue
in designer. - Do not close designer window. Close VS.
- Start solution (double-click
sln
file). - As soon as designer loads window you will see
TextBlock
displayFalse
.
WTF? Can someone confirm that (or is it my VS 2015 bug)?
I would really like to know how designer works: how window is loaded, which events/methods are used, etc. It seems window constructor (non-static one) is not executed (anything put there is not happening in design time), how is the window then created and displayed?