我只是在寻找一个示例项目,以了解我应该如何实现我的应用程序。
就像在 torrent 文件中一样,我想通过网站链接在 WPF 应用程序中打开并触发一个事件。我该怎么做?
最佳答案
好的。这是我解决它的方法。
- 我正在添加注册表项以首先注册自定义 URL Scheme
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\KA] @="URL:KA Protocol" "URL Protocol"=""
[HKEY_CLASSES_ROOT\KA\shell]
[HKEY_CLASSES_ROOT\KA\shell\open]
[HKEY_CLASSES_ROOT\KA\shell\open\command] @="\"C:\Users\me\Desktop\myapp\myapp.exe\" \"%1\""
在 Internet Explorer 中键入 KA://myargument 以尝试处理 myapp.exe
在 App.cs 中像这样处理我的 WPF 应用
public partial class App : Application { void App_Startup(object sender, StartupEventArgs e) { for (int i = 0; i != e.Args.Length; ++i) { if (e.Args[i].StartsWith("ka:")) { int index = e.Args[i].IndexOf(':') +1; string argg= e.Args[i].Substring(index, e.Args[i].Length - index); // handling argument here } } Shell mainWindow = new Container(); mainWindow.Show(); } }
关于.net - 与 .NET 和 WPF 的磁力链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133018/