locked
Sending data from one page to another RRS feed

  • Question

  • I have a page which allows the user to choose certain data, then the window naviagtes to another page...but i want the data the person chose in the 1st page to be sent to the second page so that it can be used in my .cs code.

    thanks!..awaiting reply

    Friday, May 7, 2010 9:42 PM

Answers

  • In the xaml.cs file for your 2nd page, add something like:

    public static string FileName { get; set; }

    Then, in your button event handler (select the button, go to the properties panel, click the lightning bolt looking icon, type a name into the click line, press enter), you can then do something like:

    ClassNameOf2ndScreen.FileName = this.NameOfYourListBox.SelectedItem as string;

    Then in the constructor of your 2nd screen, you could use that variable to determine the state of the page,

    if(!string.IsNullOrWhitespace(FileName))

    { play(); }

     

    You can get the command line args in WPF using:

    string[] args = Environment.GetCommandLineArgs();

    I believe args[0] will be the name of your exe, and args[1] should then be the filepath.  Not 100% sure on that.

    • Marked as answer by ICode. _ Monday, May 10, 2010 8:49 PM
    Monday, May 10, 2010 8:45 PM
    Moderator

All replies

  • Are you using Blend 3 or 4? What type of project? SketchFlow or regular WPF/SL?  WPF or SL?  What does the data consist of? How do you navigate to the next "page"? What are the "pages"?

    Please provide more information and we can try to help you further.

    Monday, May 10, 2010 7:37 PM
    Moderator
  • i'm using blend 3 and its a WPF project.

    say for instance i have a page which shows a playlist. when the user clicks one of the items, i want that filename(D:\music\music.mp3) to be sent to the next page which will play it.

     

    and also if u could....can u tell me how to get the filename of an file that a user doubleclicks in the normal explorer.exe.

    i.e. if a user clicks on the D:\music\music.mp3 and opens my WPF project i want it to automatically play it.....how do you send the filepath to the program.

    Monday, May 10, 2010 7:46 PM
  • This will have a lot of assumptions, so hopefully it will still be helpful:

    Assuming you have a listbox of some sort, where a user can select an item, and a button that triggers the next page, and that you are using the wpf navigation framework to display pages, you could make the item to play be a static member of the 2nd page's class, and the event handler from the first page could use the selected item to set that member variable. Then you can use the wpf navigation framework to navigate to the 2nd page, which could start playing based on the state of the static member variable.

     

    As for the other question, you should search bing for windows file associations, that is a big topic to try to answer in a forum.  Once it is registered, windows will launch your program with the filename on the command line.

    Monday, May 10, 2010 8:13 PM
    Moderator
  • you are assuming right. But, could you explain more??...

    "you could make the item to play be a static member of the 2nd page's class, and the event handler from the first page could use the selected item to set that member variable. "...more explination on this.

     

    yea, i know about the registered thingy..but when it launches it on the command line, u get the filepath from the args[] (the paramater of the main)...(so i've heard). My question is how exactly do you retreive it from the args[]?

     

    thanks!

    Monday, May 10, 2010 8:28 PM
  • In the xaml.cs file for your 2nd page, add something like:

    public static string FileName { get; set; }

    Then, in your button event handler (select the button, go to the properties panel, click the lightning bolt looking icon, type a name into the click line, press enter), you can then do something like:

    ClassNameOf2ndScreen.FileName = this.NameOfYourListBox.SelectedItem as string;

    Then in the constructor of your 2nd screen, you could use that variable to determine the state of the page,

    if(!string.IsNullOrWhitespace(FileName))

    { play(); }

     

    You can get the command line args in WPF using:

    string[] args = Environment.GetCommandLineArgs();

    I believe args[0] will be the name of your exe, and args[1] should then be the filepath.  Not 100% sure on that.

    • Marked as answer by ICode. _ Monday, May 10, 2010 8:49 PM
    Monday, May 10, 2010 8:45 PM
    Moderator
  • Thanks alot man!!!!!, i really appriciate it!

    Monday, May 10, 2010 8:49 PM
  • thanks man, very good, its really help ful
    • Proposed as answer by iwkannan Wednesday, January 25, 2012 9:33 AM
    • Unproposed as answer by Chuck HaysModerator Wednesday, January 25, 2012 2:29 PM
    Wednesday, January 25, 2012 9:32 AM
  • Hi check the below link. this will help you.

    http://dotnetpools.com/Article/ArticleDetiail/?articleId=47
    Saturday, October 20, 2012 3:15 PM
  • Hi check the below link. this will help you.


    http://dotnetpools.com/Article/ArticleDetiail/?articleId=47
    Saturday, October 20, 2012 3:17 PM