MVVM call OnAppearing()

DeviC3DeviC3 Member ✭✭

Is there way to call OnAppearing() event in my ViewModel ?
I tried a lot but it looks like ther's no way.



  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Why are you trying to do that?

  • DeviC3DeviC3 Member ✭✭
    In my viewmodel class. It should somehow inherit from Content Page
  • JoeMankeJoeManke USMember ✭✭✭✭✭

    But why? What do you intend to do that you need to call a lifecycle method instead of letting it be called by the framework?

  • DeviC3DeviC3 Member ✭✭
    Listview in page should be always updated so I think it is needed to call OnAppearing
  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Sounds like you're trying to do work in your code-behind instead of your ViewModel. Instead, when OnAppearing is called, your page should call a ViewModel method to update your data and bindings.

  • DeviC3DeviC3 Member ✭✭

    Ok, now I think I understand, it's my second time in mvvm, tommorow I will try this and post code. Thank You for help for now.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    You can convert your event in a Command using behavior.forms package
  • NMackayNMackay GBInsider, University mod

    Take inspiration from Prismlib which has great hooks into navigation events

    As @AlessandroCaliaro says, you could hook into the page's behaviors and execute a command

    <ContentPage xmlns="" 
                 Title="InvokeCommand Demo" 
            <local:InvokeCommandDemoPageViewModel />
            <behaviors:EventHandlerBehavior EventName="Appearing">
                <behaviors:InvokeCommandAction Command="{Binding PageAppearingCommand}" />
            <behaviors:EventHandlerBehavior EventName="Disappearing">
                <behaviors:InvokeCommandAction Command="{Binding PageDisappearingCommand}" />

Sign In or Register to comment.