locked
OnSessionChanged - Only called after first login? Problems with persisted session RRS feed

  • Question

  • Hi, I wrote a little browser app, to browse the contents on SkyDrive. The session is persisted after a user logged in, all contents are shown. When I leave the application, and return to it, the SignIn-Button re-authenticates the session automatically. But OnSessionChanged is not fired again. In my ViewModel, I check the status of the session, after OnSessionChanged was executed via

    <i:EventTrigger EventName="SessionChanged" >    
    <Command:EventToCommand Command="{Binding SessionChangedRelayCommand,Mode=OneWay}" PassEventArgsToCommand="True"></Command:EventToCommand>
    </i:EventTrigger>
    

    So, is there any event I can utilize when the SignIn-Button control has logged in again?

    Thank you.

    Ilija

     


    http://embdocumentinhalator.codeplex.com/
    Thursday, December 8, 2011 5:05 PM

Answers

  • Hi,

    The issue is likely related to the EventTrigger and not to MVVM Light itself. The EventTrigger is part of the System.Windows.Interactivity DLL released by the Blend SDK team. 

    Some events do not trigger the EventTrigger, notably, events that are not routed. I'll need to test to confirm this but I think this is what you are seeing. If for example you replace the EventToCommand with another action, for example a GoToStateAction, my guess is that you won't see it work either. But as I said, I will test to confirm.

    In my apps that use the Live SDK, I took the pragmatic approach to handle the event in code-behind, and to call methods on the VM from there.

    Cheers

    Laurent


    Software engineering - http://www.galasoft.ch

    • Marked as answer by Ilija Injac Friday, February 1, 2013 5:58 PM
    Friday, February 1, 2013 5:56 PM
  • Hey Ilija,

    Have you tried subscribing to the event on the button without using frameworks like MVVM light. We were unable to repro this internally, the session changed event args is getting triggred on app resume.

    Thanks

    Deepesh

    • Marked as answer by Ilija Injac Friday, December 9, 2011 12:34 AM
    Friday, December 9, 2011 12:20 AM

All replies

  • Hey Ilija,

    Have you tried subscribing to the event on the button without using frameworks like MVVM light. We were unable to repro this internally, the session changed event args is getting triggred on app resume.

    Thanks

    Deepesh

    • Marked as answer by Ilija Injac Friday, December 9, 2011 12:34 AM
    Friday, December 9, 2011 12:20 AM
  • Hi Deepesh,

    thank you for your quick reply. No, I have not tried it. I will try it, and let you know how it was going.

    Thank you again.

    Ilija

     


    http://embdocumentinhalator.codeplex.com/
    Friday, December 9, 2011 12:33 AM
  • Hi Deepesh,

     

    works like a charm... I will write some message to Laurent about it. Maybe I've done something wrong.

     

    Ilija

     


    http://embdocumentinhalator.codeplex.com/
    Friday, December 9, 2011 12:48 AM
  • thanks for the update. Could you keep me in the loop with your discussion with Laurent. My email address is my [lastname].[firstname]@microsoft.com

     

    Friday, December 9, 2011 7:45 AM
  • No Problem.
    http://embdocumentinhalator.codeplex.com/
    Friday, December 9, 2011 2:38 PM
  • Hi Deepesh and llija, i have same issue with my application. Using RelayCommand<LiveConnectSessionChangedEventArgs>, the SessionChanged event triggers only if sign-in button is touched by the user. Can you tell me how can i do to solve this problem?

    Thanks.

    Marco

    <my:SignInButton x:Name="btnSignin"
                                 Grid.Row="2"
                                 TextType="SignIn"
                                 ClientId="{Binding Path=ClientID}"
                                 Scopes="{Binding Path=Scopes}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SessionChanged">
                            <Command:EventToCommand Command="{Binding Path=SessionChangedCommand, Mode=TwoWay}" PassEventArgsToCommand="True" />
                        </i:EventTrigger>                    
                    </i:Interaction.Triggers>
                </my:SignInButton>
    
    
    -----------------------------------------------------------
    
    private RelayCommand<LiveConnectSessionChangedEventArgs> _sessionChanged;
    
            public RelayCommand<LiveConnectSessionChangedEventArgs> SessionChangedCommand
            {            
                get
                {
                    return _sessionChanged
                        ?? (_sessionChanged = new RelayCommand<LiveConnectSessionChangedEventArgs>(
                                              (e) =>
                                              {
                                               //something to do with "e"   
    })); } }

    Friday, February 1, 2013 5:38 PM
  • I think you should post that  on the codeplex page where MVVM-Light is hosted. I think Laurent can help us out on that problem. I still have no solution for that. And sorry @Deepesh for not replying. But had to do a workaround and keep moving. I will try to ping Laurent on Twitter.

    http://blog.mecum.biz

    Friday, February 1, 2013 5:45 PM
  • Hi,

    The issue is likely related to the EventTrigger and not to MVVM Light itself. The EventTrigger is part of the System.Windows.Interactivity DLL released by the Blend SDK team. 

    Some events do not trigger the EventTrigger, notably, events that are not routed. I'll need to test to confirm this but I think this is what you are seeing. If for example you replace the EventToCommand with another action, for example a GoToStateAction, my guess is that you won't see it work either. But as I said, I will test to confirm.

    In my apps that use the Live SDK, I took the pragmatic approach to handle the event in code-behind, and to call methods on the VM from there.

    Cheers

    Laurent


    Software engineering - http://www.galasoft.ch

    • Marked as answer by Ilija Injac Friday, February 1, 2013 5:58 PM
    Friday, February 1, 2013 5:56 PM
  • Thanks for replies. I'll go to follow Laurent's way and manage it from code-behind.

    Best regards.

    Marco

    Friday, February 1, 2013 6:06 PM
  • Hi Guys,

    I also wanted to handle this on the ViewModel rather than the code behind of the viewpage, so I played around with the code to get the following working for me:

    ViewModel:

    public MainViewModel(INavigationService navigationService,
                IApplicationManifestService applicationManifestService)
                : base(navigationService, applicationManifestService)
            {
                this.Items = new ObservableCollection<Recipe>();
                this.Categories = new ObservableCollection<Category>();
                this.ViewRecipeCommand = new RelayCommand<Recipe>((o) => this.ViewRecipe(o));
                this.LoginCommand = new RelayCommand<Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs>((e) => OnLogin(e));
                if (!IsDataLoaded)
                {
                    LoadData();
                }
            }
    
    private async void OnLogin(Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
            {
                if (e != null && e.Status == LiveConnectSessionStatus.Connected)
                {
                    this.liveClient = new LiveConnectClient(e.Session);
                    await this.Authenticate();
                }
                else
                {
                    this.liveClient = null;
                    // todo:handle the logout or the failure here
                }
            }

    The XAML:

    <live:SignInButton x:Name="SignInButton" ClientId="xxx" Scopes="wl.signin wl.basic wl.offline_access">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SessionChanged">
                                    <cmd:EventToCommand Command="{Binding LoginCommand, Mode=OneWay}" CommandParameter="{Binding Path=SessionChanged, ElementName=SignInButton}" PassEventArgsToCommand="True"  />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </live:SignInButton>

    This worked for me and the Command on the ViewModel is firing as expected.



    Edit: Sorry, it works except it does not fire on app start as previously stated.
    Monday, October 7, 2013 8:26 PM