3

Is there some trick that is known to tell blend to stop trying to set a startupURI in my app.xaml? I googled but didn't see anything so I figured I would ask here.

I use a startup routine and instantiate mainwindow myself. Every once and a while blend likes to toss in the startupURI="MainWindow.xaml" when I let it compile. Occasionally I see some message along of the lines of "There is no startup scene associated with this project. Would you like blend to blah blah fix it?" or something along those lines. I click cancel/no yet it still tosses a gremlin in my code. Internal to blend there is some mechanism for checking for this property or it wouldn't complain via dialog box to me. So how do I just tell it "no thanks blend, i'm good without that?", lol.

Its quite annoying. I open blend to do something simple like using a color picker and use it to compile because VS2010 isn't open. My result is two mainwindows. But it does not do it every time so it's not a repeatable behavior. The compiler just acts out randomly.

edit: I'm using blend 4 but I saw this happen when i was using blend 3 also.

TWood
  • 2,563
  • 8
  • 36
  • 58
  • I second that, it's clearly annoying when you need to instantiate your window from the statup code !! – Aurelien Ribon Oct 15 '10 at 20:31
  • I hope someone from the Blend team frequents this forum and can include a fix for this or at least a checkbox option in the next version of Blend. This still happens to me at least 3 times a week. I try to not build my project with blend but many times I must do so in order for my visuals to refresh on the artboard. When you build it takes the active .xaml file (window, page, usercontrol) and sets it as the startup. – TWood Nov 10 '10 at 15:41

1 Answers1

0

This is a horrible, terrible hack, but hey, it works. By default, StartupUri is null, but you can't set it to null using the property, so you can go around the property if you like to live on 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 so:

protected override void OnStartup(StartupEventArgs e)
{
    FixStartupUri();
    base.OnStartup(e);
    // Do the rest of your startup stuff.
}
ungood
  • 582
  • 6
  • 9