Prism - Replacing MainPage - Switch with Toggled Behaviour on Old MainPage firing

ledragonledragon Member ✭✭✭

Hi,

Wonder if anyone can help with this. I have a MainPage with a Switch with a Behaviour on the Toggled event:

<Switch HeightRequest="40"
        Grid.Column="2" Grid.Row="0"
        HorizontalOptions="EndAndExpand"                        
        IsToggled="{Binding IsSetOffline}">
        <Switch.Behaviors>
            <b:EventToCommandBehavior EventName="Toggled" 
                Command="{Binding OfflineToggledCommand}"
                EventArgsConverter="{converters:SwitchOnToggledEventArgsConverter}"/>
        </Switch.Behaviors>
     </Switch>

I want to replace the MainPage with a MasterDetail so I'm navigating with Prism as so:

await NavigationService.NavigateAsync(new Uri("/EditJobMaster/NavigationPage/EditRFIs", UriKind.Absolute), parameters, false, false);

However, when the MainPage is switched, if the Switch is set to True (Toggled) the Toggled event is firing (i.e resetting to False).

Does anyone have any understanding of why and how I can prevent this?

Thanks in advance

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 2019

    Switch with Toggled Behaviour on Old MainPage firing

    Just use Application.Current.MainPage method to replace the main page.

    Application.Current.MainPage = new MasterDetailPage();
    

    Tutorial:
    https://xamarinhelp.com/navigating-xamarin-forms/

  • ledragonledragon Member ✭✭✭
    edited October 2019

    @Jarvan Hi Thanks for the Answer...apologies I should've mentioned I am passing Prism Navigation Parameters to the MasterDetail.

    Do you know how to do this when navigating via:

    Application.Current.MainPage = new MasterDetailPage();

Sign In or Register to comment.