Example #1
0
        private void friendsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (friendsListView.SelectionMode == ListViewSelectionMode.Single)
            {
                // If selected item is null (no selection) do nothing
                if (friendsListView.SelectedItem == null)
                {
                    return;
                }

                // Retrieve the selected friend and toggle the chat buttons
                FriendsListEntry selectedFriend = friendsListView.SelectedItem as FriendsListEntry;

                // Setup the chat variables and open the chat window if we already have a session
                if (selectedFriend.sessionEstablished)
                {
                    // Set the binding variables to the data from the current friend we are chatting with and hide the chat buttons
                    AppServices.friendsData.currFriendsName   = selectedFriend.username;
                    AppServices.friendsData.chatHistory       = selectedFriend.history;
                    AppServices.friendsData.sendButtonEnabled = true;
                    selectedFriend.chatButtonsVisible         = false;
                    lastSelected = null;
                    friendsListView.SelectedItem = null;
                    Frame.Navigate(typeof(ChatPage));
                }
                else
                {
                    // Stop showing the chat buttons for the last selected friend. If the last selected and current selected are the same toggle the buttons
                    //	and return
                    if (lastSelected != null)
                    {
                        if (lastSelected.Equals(friendsListView.SelectedItem))
                        {
                            lastSelected.chatButtonsVisible = !lastSelected.chatButtonsVisible;
                            friendsListView.SelectedItem    = null;
                            return;
                        }
                        else
                        {
                            lastSelected.chatButtonsVisible = false;
                        }
                    }


                    selectedFriend.chatButtonsVisible = true;

                    lastSelected = selectedFriend;
                }

                friendsListView.SelectedItem = null;
                return;
            }
            else if (friendsListView.SelectionMode == ListViewSelectionMode.Multiple)
            {
                return;
            }
        }