question

SirnHirmeza-5338 avatar image
0 Votes"
SirnHirmeza-5338 asked SirnHirmeza-5338 commented

Best Way To Get SelecetdItem From The Shell.SearchHandler

What will be the best way to perform an operation when the object gets selected from the search handler dropdown? I know we can create a custom class that extends the SearchHandler and impelement some of the methods, but this will not help when we use the Searchhandler in multiple pages then we will have to create a class for every page and route to itself in the OnItemSelecetd method.
For instance, if page A has SearchHandler and select an Item from the dropdown will trigger the OnItemSelecetd and use routing to route to page A. Same thing applies to page B which will have it's own class that extends SearchHandler and trigger OnItemSelected and route to itself.

I am trying to find a way that handles the selecetd item and perform operation while I am in the same class.

I used SelectedItem which I know now it is read only, but it works fine. The only issue I have when I used it 198462-2022-05-03-00h23-30.pngis the error I get that says "Property does not have accessible setter".
If we could bind the SelecetdItem, that will solve the problem.198436-2022-05-03-00h17-05.png


dotnet-xamarin
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Firstly, do you want to create a parent class extends ContentPage that set SearchHandler in this parents class, child class extends parent class and does not need to add SearchHandler? Or do you want to create a custom SearchHandler for all of pages?

Do you have same Itemsource for your all of Searchhandlers? If not, we have to create custom Searchhandlers for every pages.

0 Votes 0 ·

Hello LeonLu,
I have the parent class that extends the ContentPage. Inside the parent class constructor, I am binding to a new class using binding context. I am using MVVM pattren. The bindable class is extending base class. If I create the custom SearchHandler for all pages, is there a way to route to the same page where I am selecting the item from the searchHandler dropdown?

For Instance, If I am selecting an item from SearchHandler dropdown that is in page A, it navigates to page A. Same thing applies to page B. When I select an item from page B, it should navigate to page B.

ItemSource is the same for all SearchHandler, but the action is different for each page. The pages share the same template as well.
Thank you so much for any kind of feedback.

0 Votes 0 ·
LeonLu-MSFT avatar image LeonLu-MSFT SirnHirmeza-5338 ·

If I am selecting an item from SearchHandler dropdown that is in page A, it navigates to page A. Same thing applies to page B. When I select an item from page B, it should navigate to page B.

Do you want to Navigate in current tab? For example, you have a tab A that show aboutPage, when you selecting an item from SearchHandler, then navigate to detailspage in current tab. Others tabs do not have any effects. If so, you could achieve it by relative routes like following thread.

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#relative-routes

0 Votes 0 ·
Show more comments

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered SirnHirmeza-5338 commented

Hello,​


I download this Xaminals demo, you can open the AppShell.xaml.cs, this Routes is public Dictionary<string, Type> Routes { get; private set; } = new Dictionary<string, Type>(); not the Xamarin.Forms.Shell.Routes, they have same name, but they have different achievement, you can add public Dictionary<string, Type> Routes { get; private set; } = new Dictionary<string, Type>(); in your AppShell.xaml.cs, then RegisterRoutes like this demo.

Best Regards,

Leon Lu



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That worked for me!!
Thank you so much LeonLu.

0 Votes 0 ·