B
B
bestdk22017-03-24 11:57:26
WPF
bestdk2, 2017-03-24 11:57:26

Why isn't InitializeComponent running?

Good afternoon.
Develop an application that works with conditional files. And you need to open files of some resolution by double click. So far I decided to do it without entries in the register, but simply through opening with the help and specifying the path to the file.
App.xaml.cs code:

protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            if (e.Args.Length != 0)
            {
                Uri uri = new Uri(e.Args[0]);
                this.Properties["ArbitraryArgName"] = uri.LocalPath;
                ASKD.MainWindow window = new ASKD.MainWindow();
  
                window.Show();
            }   
        }

In MainWindow on the Loaded method I write the following:
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { // запустится когда все дети загрузятся
                
                if (Application.Current.Properties["ArbitraryArgName"] != null)
                {
                    CurrentPath = Application.Current.Properties["ArbitraryArgName"].ToString();

                    if (File.Exists(CurrentPath))
                    {
                        
                       //делаю всякое
                    }
                }
            }));

As a result, the application does not start. Rather, it comes to InitializeComponent () in MainWindow and nothing happens safely. However, if you open a file in the same folder as the executable, then a miracle happens. How to solve such a problem?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-03-24
@bestdk2

here the campaign contains your answer (at the very bottom)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question