我有一个不错的小作业组织者,我想添加一个备份选项。但我不希望它在普通的 xml 文件或其他文件中,因为文件损坏的可能性。那么如何制作程序知道的文件扩展名,并且可以保存并使用 .asog 文件扩展名打开呢?
6914 次
3 回答
3
于 2010-01-20T02:53:19.777 回答
3
如果您想将扩展名为 (.magi) 的文件与您的 WPF 应用程序相关联,我建议您使用InnoSetup来执行此操作。
例如,我开发了一个名为 MAGI 的 WPF 应用程序。我们将图标与“ .magi”文件相关联,当用户单击“ .magi”文件时,它会启动应用程序并直接在应用程序中打开它。
使用 InnoSetup 轻松修改注册表
只需在您的 iss 文件中添加此指令:
[Setup]
ChangesAssociations=yes
[Registry]
Root: HKCR; Subkey: ".magi"; ValueType: string; ValueName: ""; ValueData: "MyMAGIApplication"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "MyMAGIApplication"; ValueType: string; ValueName: ""; ValueData: "Program MAGI"; Flags: uninsdeletekey
Root: HKCR; Subkey: "MyMAGIApplication\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\MAGI.EXE,0"
Root: HKCR; Subkey: "MyMAGIApplication\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\MAGI.EXE"" ""%1"""
解析“启动”方法中的参数
我们使用Startup
主 Xaml 中的属性,以便像调用有用的主方法一样调用您的解析器。
<Application x:Class="MAGI.View.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="AppStartupMainMagi" >
</Application>
在代码隐藏中我们添加了这个方法
/// <summary>
/// Call with Startup property in App.xaml
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AppStartupMainMAGI(object sender, StartupEventArgs e)
{
String[] arguments = Environment.GetCommandLineArgs();
if (arguments.GetLength(0) > 1)
{
if (arguments[1].EndsWith(".magi"))
{
string filePathFormMainArgs = arguments[1];
if(isFileMagiValid(filePathFormMainArgs))
{
// Step 1 : deserialize filePathFormMainArgs
// Step 2 : call the view "File oepn" in the application"
}
}
}
else {
// Call the view "welcome page application"
}
}
于 2014-11-18T11:37:45.547 回答
1
您可以使用安装项目或 ClickOnce 安装添加文件扩展名。设置完成后,用户可以双击 .asog 文件,然后您的应用程序将被调用,文件名作为 main 参数数组中的第一个条目。
于 2010-01-20T02:51:04.463 回答