Enquiry on doing open dialog RRS feed

  • Question

  • User326503 posted

    I am going to include open dialog in my developed xamarin applications. I had added these code in main.cs.

    I get the code from https://developer.xamarin.com/guides/mac/user-interface/working-with-dialogs/#TheOpenDialog

    var dlg = NSOpenPanel.OpenPanel; dlg.CanChooseFiles = true; dlg.CanChooseDirectories = false; dlg.AllowedFileTypes = new string[] { "txt", "html", "md", "css" };

            if (dlg.RunModal() == 1)
                // Nab the first file
                var url = dlg.Urls[0];
                if (url != null)
                    var path = url.Path;
                    // Create a new window to hold the text
                    var newWindowController = new WindowController();
                    // Load the text into the window
                    var window = newWindowController.Window as MainWindow;
                    window.Text = File.ReadAllText(path);
                    window.RepresentedUrl = url;

    But the error shown

    Friday, May 26, 2017 10:02 AM

All replies

  • User125801 posted

    This code should go in AppDelegate.cs not Main.cs. Take a look at the sample code here for an example:


    Friday, May 26, 2017 11:26 AM