prevent blend from adding a startupURI to application?
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.
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.
}
精彩评论