locked
What's wrong with this in c++?

    Question

  • In the xaml.h file under protected

    void OnQuerySubmitted(Windows::ApplicationModel::Search::SearchPane^ sender, Windows::ApplicationModel::Search::SearchPaneQuerySubmittedEventArgs^ e);

    In xaml.cpp

    void MainPage::OnQuerySubmitted(SearchPane^ sender, SearchPaneQuerySubmittedEventArgs^ e) {
    	auto queryText = e->QueryText;
    	wstring query = wstring(queryText->Data());
    	
            
    			if(queryText==L"inductance") maininductance->Visibility=Windows::UI::Xaml::Visibility::Visible;}        
    }


    void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
    {
    	(void) e;	// Unused parameter
    	InitalizeTrialPlumbing();
    	MainPage::UpdateTrialStatusPanel();
    	token = searchPane->SuggestionsRequested += ref new TypedEventHandler<SearchPane^, SearchPaneSuggestionsRequestedEventArgs^>(this, &MainPage::OnSearchPaneSuggestionsRequested);
    	SearchPane::GetForCurrentView()->ShowOnKeyboardInput = true;
    	SearchPane::GetForCurrentView()->QuerySubmitted += OnQuerySubmitted;
    }
    
    
    void MainPage::OnNavigatedFrom(NavigationEventArgs^ e)
    {
        searchPane->SuggestionsRequested -= token;
    	SearchPane::GetForCurrentView()->ShowOnKeyboardInput = false;
    	SearchPane::GetForCurrentView()->QuerySubmitted -= OnQuerySubmitted;
    }

    I know there's an error with

    SearchPane::GetForCurrentView()->QuerySubmitted += OnQuerySubmitted;

    and

    SearchPane::GetForCurrentView()->QuerySubmitted += OnQuerySubmitted;

    But what?

    Thursday, August 15, 2013 4:40 PM

Answers

  • There are a couple of problems with this.

    For the compile problem, you can use the following line of code to get rid of the compile error when adding an event handler:

    SearchPane::GetForCurrentView()->QuerySubmitted += ref new TypedEventHandler<Windows::ApplicationModel::Search::SearchPane^, Windows::ApplicationModel::Search::SearchPaneQuerySubmittedEventArgs^>(this, &MainPage::OnQuerySubmitted);

    You cannot unregister the event handler when you navigate away from the page.

    This means that you will need to place your adding the event handler code in the constructor of the page which will get called once when the page gets instantiated.

    Why are you also restricting the search contract per page? Why are you not targeting the search contract to work at the "App" level?

    You can take a look at the Search contract sample to see how it is done: http://code.msdn.microsoft.com/Search-contract-sample-add25823


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    • Marked as answer by RandyPete Thursday, August 15, 2013 10:16 PM
    Thursday, August 15, 2013 9:50 PM
    Moderator

All replies

  • What's the error? Is a runtime or compile time error?
    Thursday, August 15, 2013 9:45 PM
  • There are a couple of problems with this.

    For the compile problem, you can use the following line of code to get rid of the compile error when adding an event handler:

    SearchPane::GetForCurrentView()->QuerySubmitted += ref new TypedEventHandler<Windows::ApplicationModel::Search::SearchPane^, Windows::ApplicationModel::Search::SearchPaneQuerySubmittedEventArgs^>(this, &MainPage::OnQuerySubmitted);

    You cannot unregister the event handler when you navigate away from the page.

    This means that you will need to place your adding the event handler code in the constructor of the page which will get called once when the page gets instantiated.

    Why are you also restricting the search contract per page? Why are you not targeting the search contract to work at the "App" level?

    You can take a look at the Search contract sample to see how it is done: http://code.msdn.microsoft.com/Search-contract-sample-add25823


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    • Marked as answer by RandyPete Thursday, August 15, 2013 10:16 PM
    Thursday, August 15, 2013 9:50 PM
    Moderator
  • Thank you, that made it work perfectly.

    I purposely restrict the search contract to the page.  Making it app level would work against what I'm trying to do.

    Thursday, August 15, 2013 10:16 PM