Pass value from FlyoutItem

Lloyd Sheen 1,391 Reputation points

In my app I can navigate to a page and pass an object which that page is to work with. It also has a FlyoutItem which will navigate to that page (but with no object to deal with). The page has a button which will show a popup allowing the user to select an object to deal with. At present I can cause the method which the button will call but if I have gotten there with an object passed thru the following : await Shell.Current.GoToAsync($"{nameof(TeamsPage)}", navigationParameter); it will have as the background the display of the object sent as navigationParameter and will show the popup which is not necessary. If I use the FlyoutItem the user will at present have to click the button to get the popup to select an item to display. Is there a way to send (lets say a string as a parameter so that the ApplyQueryAttributes method is called (it is called using the above code) so that I will know that an item needs to be selected. The best way would be that the FlyoutItem has a property which can be set so that the app knows to show the popup without a button click.

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,977 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,951 Reputation points Microsoft Vendor


    By referring to the official documentation, we could see that there are two types of components in MAUI's flyout, flyoutitem and menuitem. Among them, menuitem allows custom click events or commands and passes parameters.

    Therefore, for your needs, it is more recommended to use to menuitem, so that you could use await Shell.Current.GoToAsync ($"{nameof(TeamsPage)}", navigationParameter) in the event to pass parameters, please refer to Menu items for more details.

    The MenuItem class has a Clicked event, and a Command property. Therefore, MenuItem objects enable scenarios that execute an action in response to the MenuItem being tapped.

    Best Regards,

    Alec Liu.

    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 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jack1 0 Reputation points

    It sounds like you want to pass a parameter to a FlyoutItem in Xamarin Forms. According to Stack Overflow, you can use Xamarin.Essentials: Preferences to store the data at Main Shell and get/use it in the 'page1' and 'page2'. In Main Shell, store the data: public FlyoutMainShell (string name) { InitializeComponent (); Preferences.Set ("uesr_name", name); } In other page, get the value: var name = Preferences.Get("uesr_name", string.Empty); You can also use query parameters to pass data between pages. The navigation needs to have items that will navigate to the same page, but should pass a query parameter which the page will then use to filter the data on the page. Check here

    0 comments No comments