我的应用程序仅适用于我和同事,所以我不在乎它是Click-Once还是Copy-the-exe。我希望能够在Windows资源管理器中单击具有给定扩展名的文件,并启动我的程序并打开该文件。我无法获取它来捕获文件名。WPF;点击一次;双击文件启动; VS 2008
表面上的解决方案:
我想要的代码如下,并在这一点上所有我想要做的就是把点击文件名的文本框中。我怀疑我的相关无知是关于如何从Windows资源管理器引用一次性应用程序。当我建立时,我最终得到一个名为setup.exe的文件,一个名为Wis.application的文件,当我点击“setup”安装它时,我最终得到了一个“Click-once application reference”类型的快捷方式,在“ C:\ Users \ ptom \ AppData \ Roaming \ Microsoft \ Windows \ Start Menu \ Programs \ Wis“。我试着将文件与通过安装创建的快捷方式相关联,并将文件与setup.exe关联。当我点击该文件时,应用程序将启动,但表示 AppDomain.CurrentDomain.SetupInformation.ActivationArguments为空。 (通过“指示”我的意思是文本框被填充来自我测试的文本以查看它是否为空)。如果我从调试中运行应用程序,或者只是通过从开始菜单运行应用程序,它会按照我所期望的那样进行,遵循指示ActivationArguments不为空的代码路径,但其ActivationData(string [])的长度0
下面是从app.xaml.cs代码
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
namespace Wis
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// Check if this was launched by double-clicking a doc. If so, use that as the
// startup file name.
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments == null)
{
this.Properties["DoubleClickedFileToLoad"] = "There were no activation arguments AGAIN";
}
else
{
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null
&& AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
{
this.Properties["DoubleClickedFileToLoad"] =
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
}
else
{
this.Properties["DoubleClickedFileToLoad"] = "Type in a file name";
}
}
}
}
}
感谢
我粘贴了你的代码;你有一个名为ApplicationDeployment的对象;我一开始就把它切掉了,它工作。我必须添加一个对System.Deployment的引用来使用第一个测试。 – 2010-11-20 20:37:02