更新3
这实际上是由我包含的使用ILMerge的构建后操作造成的。有关更多细节,请参见here
Update2
这似乎不是直接由添加命令行支持造成的,但我仍然不知道是什么原因造成的。有关更多详细信息,请参阅SO question。
更新
在进行了以下更改以允许命令行支持之后,我无法在所有断点上执行此消息的程序:
当前不会命中断点。此文档没有加载任何符号。
我检查了this SO answer,发现我丢失了Microsoft.VisualStudio.Debugger.Runtime.pdb文件,但是我不知道它去了哪里。
有什么原因会因为App.xaml更新而发生这种情况吗?
我有一个WPF应用程序,需要实现命令行参数。
在this SO question的回答之后,我修改了App.xaml以删除StartUpUri属性:
<Application x:Class="WpfFileDeleter.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfFileDeleter"
>
<Application.Resources>
</Application.Resources>
</Application>然后,我向App.xaml.cs添加了一个覆盖方法。
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
e.Args.Contains("MyTriggerArg")
{
// Do some stuff
}
}但是,在OnStartUp顶部插入一个断点并在Visual中调试应用程序之后,它只挂在就绪状态,但从来不允许我执行程序。
我为StartUpUri尝试了以下值
StartUpUri = "App.xaml"
StartUpUri = "App.xaml.cs"
StartUpUri = "App.xaml.cs.OnStartUp"但是应用程序只是抛出一个“无法定位资源”的IOException。
发布于 2016-09-07 12:06:52
根据伦理逻辑的回答,在app_start事件处理程序中定义启动参数就足够了。如果从xaml中删除starupuri,则需要在sratup处理程序中定义其他内容,而不是
发布于 2016-09-07 12:08:18
所以App.xaml看起来是这样的:
<Application x:Class="MonitorTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MonitorTool"
StartupUri="Views/SplashScreen.xaml"
Exit="Application_Exit">
</Application>在我的App.xaml.cs中,我得到了以下代码:
public partial class App : Application
{
private void Application_Exit(object sender, ExitEventArgs e)
{
//Some settings savin here...
}
}当您对StartUp使用XAML方式时,请确保名称空间是正确的。我把我的MainWindow.xaml放在一个叫做Views的文件夹里。
或者创建这样的启动:Startup="Application_Startup"
并在App.xaml.cs文件中创建一个方法。再次检查名称空间,以确保所有内容都在这里。
因为你的应用程序正在构建,我想这应该是可行的,你至少应该达到这个方法。
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow window = new MainWindow();
window.Show();
}Note
在处理参数时,不需要使用覆盖OnStartup(),只需如下所示:
private void Application_Startup(object sender, StartupEventArgs e)
{
string[] args = e.Args;
//Check for some value (for/foreach-loop) and do some stuff
MainWindow w = new MainWindow();
w.Show();
}https://stackoverflow.com/questions/39369343
复制相似问题