To prevent mixing from adding startupURI to the application?

Is there any trick that blend is known to tell you not to try to set startupURI in my app.xaml? I searched Google but didn’t see anything, so I decided that I would ask here.

I use the startup procedure and create the mainwindow instance myself. Every once in a while, I like to throw the mixture into startupURI = "MainWindow.xaml" when I let it compile. Sometimes I see a message in the lines "There is no startup scene associated with this project. Would you like bluff blah blah to fix this?" Or something along these lines. I press cancel / no, but it still throws gremlin in my code. Internal for mixing there is some mechanism for checking this property or it will not complain through the dialog box for me. So, how can I just say “no, thanks, boldly, am I right without this?”, Lol.

This is pretty annoying. I open the mixture to make something simple, for example, using a set of colors and use it to compile, because VS2010 is not open. My result is two main windows. But he does not do this every time so that this is not a repeatable behavior. The compiler just acts arbitrarily.

edit: I use blend 4, but I saw how it happened when I used blend 3.

+3
source share
1 answer

This is a terrible, terrible hack, but hey, it works. By default, StartupUri is NULL, but you cannot set it to null using a property, so you can bypass the property if you want to live around the edge.

// Dangit blend! Stop inserting a stupid StartupUri    
private void FixStartupUri()
{
    var type = typeof(Application);
    var startupUri = type.GetField("_startupUri", BindingFlags.Public
        | BindingFlags.NonPublic
        | BindingFlags.Instance);
    startupUri.SetValue(this, null);
}

Add this to your application class and call it like this:

protected override void OnStartup(StartupEventArgs e)
{
    FixStartupUri();
    base.OnStartup(e);
    // Do the rest of your startup stuff.
}
0
source

Source: https://habr.com/ru/post/1766243/


All Articles