locked
Access methods from OnFileActivated RRS feed

  • Question

  • Hi,

    I've successfully created a filetype association which appears to be opening my app when clicking on my custom text filetype in an explorer window.

    I'm now trying to tell my app what to do with the file by using 

    protected async override void OnFileActivated(FileActivatedEventArgs args)
    {
    //open my custom file type etc...
    }

    The above code is in the App.xaml.cs but I don't know how to access my methods in MainPage.xaml.cs from there. Eg - I want to call LoadVideo() here. I expected it to be something like MainPage.LoadVideo() but can't work it out. Hopefully a simple question for someone with experience.

    thanks again.


    Thursday, September 27, 2012 8:19 AM

Answers

  • Hi,
    You can use a static method to call from app.xaml.cs. 
    public static void LoadVideo(){};
    and you call it in your function
    protected async override void OnFileActivated(FileActivatedEventArgs args)
    {
    MainPage.LoadVideo();
    }
    Regards,

    Ibraheem Osama Mohamed | My Blog | @IbraheemOsamaMo

    (If my reply answers your question, please propose it as an answer)

    • Marked as answer by FSound Friday, September 28, 2012 1:41 AM
    Thursday, September 27, 2012 8:47 AM

All replies

  • Hi,
    You can use a static method to call from app.xaml.cs. 
    public static void LoadVideo(){};
    and you call it in your function
    protected async override void OnFileActivated(FileActivatedEventArgs args)
    {
    MainPage.LoadVideo();
    }
    Regards,

    Ibraheem Osama Mohamed | My Blog | @IbraheemOsamaMo

    (If my reply answers your question, please propose it as an answer)

    • Marked as answer by FSound Friday, September 28, 2012 1:41 AM
    Thursday, September 27, 2012 8:47 AM
  • and it you dont want to have it static (because you need member access) you got few other options:

     - make a medaitor class where you set the value and when setting the value trigger an event. In the page listen to the event so you can react on the changing value

     - Let the frame Navigate again and set the info you need as navigation parameter.

    Thursday, September 27, 2012 8:54 AM
  • Thanks for the extra info. Of course I'm now running into the problem that the static method is restricting access to the methods I want to invoke in MainPage.xaml.cs. Looking at your first solution I think I understand the theory but having trouble with how to implement it. An example of what I want to do below:

    in App.xaml.cs - I figure I'll need to get the file name string to load at some point but this is probably the wrong place to do it??

    protected override void OnFileActivated(FileActivatedEventArgs args)
            {
                string loadFile = args.Files[0].Name.ToString();
                MainPage.LoadVongFile();           
            }

    then in MainPage.xaml.cs - This is doesn't work

    private async void LoadVideo1()
    {
    messagetextblock.Text = "Loading video 1";
    //plus lots more code here to load video and assign settings
    }
    
    public static async void LoadVideoFile()
    {
    LoadVideo1();
    }
    Any help appreciated, this file association loading is the final step before attempting to submit my app so I'd love to get it working. As you can probably tell I haven't done a lot of programming before but am almost there :)


    Friday, September 28, 2012 2:02 AM