Reputation: 162
My WPF app has .xyz files that can open it (used the WIX installer), however, in my WPF app, I'd like to somehow capture this and call some loading functionality of the file that was double-clicked on from the File Explorer before the application was started.
Right now, if you double click the appropriate xyz file from File Explorer, it opens the application but obviously nothing else happens. Is there a way in my WPF code to detect this and call the necessary function passing in the filepath/name?
Upvotes: 2
Views: 408
Reputation: 169160
You should be able to the file path in your App.xaml.cs
class:
public partial class App : Application
{
public static string FilePath { get; private set; }
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (e.Args != null && e.Args.Length > 0)
FilePath = e.Args[0];
}
}
If you store in a static property like this, you could access it from any class in your app:
string filePath = App.FilePath;
Upvotes: 2
Reputation: 741
In Application
there is the StartUp
event where you can set your arguments.
Follow this example
Upvotes: 2