locked
Passing class objects as arguments in Windows 8 App and receive them on click event

    Question

  • The objects passed as arguments are only received an Navigation event. I want to receive them on Click Event,what should I use instead of Parameter??

    void App1::MainPage::btuN_Click(Platform::Object^ sender,Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    Variables^ data = (Variables^)e->OriginalSource;
    if (data->sNotf!=nullptr)
        Frame->Navigate(TypeName(BlankPage3::typeid), data);
    }

    I used OriginalSource, but it didn't work. Would any one help me? Thanks in Advance!

    Saturday, March 16, 2013 7:00 PM

Answers

All replies

  • Hi Waqas Ahmed Ansari,

    Actually, why you need to receive the object by button action ? 

    You can receive the object by navigation event and then access the desired functionality on click event through the object that you already received by navigation event.


    Monday, March 18, 2013 4:55 AM
  • Hi,

    I tested this on my side, but cannot reproduce this issue.

    oid App3::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	Object^ data=e->OriginalSource;
    	//Variables^ data = (Variables^)e->OriginalSource;
    if (data!=nullptr)
        Frame->Navigate(TypeName(BlankPage::typeid), data);
    
    }
    
    
    void BlankPage::OnNavigatedTo(NavigationEventArgs^ e)
    {
    	//(void) e;	// Unused parameter
    	Object^ data=e->Parameter;
    }
    

    And based on your codes, you pass a data to another page. If you want to pass value in different pages, please follow this thread.
    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/8cb42356-82bc-4d77-9bbc-ae186990cfd5/

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Friday, March 22, 2013 1:29 AM
    Monday, March 18, 2013 6:01 AM
  • The page, on which I passed object and receive on OnNavigatedTo event, is to be accessed by another page as well. So it gives an error whenever I navigate from a page from which I am not interested to pass an object. That's the problem, Sir!
    Monday, March 18, 2013 7:26 AM
  • The page, on which I passed object and receive on OnNavigatedTo event, is to be accessed by another page as well. So it gives an error whenever I navigate from a page from which I am not interested to pass an object. That's the problem, Sir!
    Monday, March 18, 2013 7:27 AM
  • Below I show the e->Clickeditem of type SampleDataItem, being registered with my home grown IOC container during the itemView_ItemClick event - it then navigates to ItemDetailPage.   The LoadState method of ItemDetailPage resolves the registered (named) type and in this demo logs the data->Description to the output window.

    I used concepts learned from the Hilo project - they use a repository where I am using a dependency injection/IOC container.   Likewise you could use a similar pattern for your purposes.

    Source: http:://passwordMgr.Codeplex.com

    disclaimer: this MVP-VM and IOC framework is in early development and I have not yet addressed some concerns, i.e., I'll have to use weak pointers as applicable to prevent memory leaks, evaluate suspending/resume support for container, etc.


    MCAD.NET C# - http://www.Global-webnet.com/Blog

    Monday, March 18, 2013 12:24 PM
  • Hi,

    In this situation, I would suggest you to store the value in local settings instead of pass the value between pages. In this way, different pages can access the data.
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh700361(v=win.10).aspx

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by BillKrat1 Tuesday, March 19, 2013 10:08 AM
    • Marked as answer by Jesse Jiang Friday, March 22, 2013 1:29 AM
    Tuesday, March 19, 2013 3:03 AM
  • Nice, I'll have to update my homegrown IOC container to use that...

    MCAD.NET C# - http://www.Global-webnet.com/Blog

    • Marked as answer by Jesse Jiang Friday, March 22, 2013 1:29 AM
    Tuesday, March 19, 2013 10:09 AM
  • A big thanks to all, I am very grateful, Sir!
    Tuesday, March 19, 2013 7:10 PM