/// <summary> /// Event handler which is triggered when this page is navigated to /// </summary> /// <param name="e">Event arguments</param> protected override void OnNavigatedTo(NavigationEventArgs e) { DataContext = null; //important part, whenever you navigate, refreshes the ViewModel - no deletion, just resetting of the DataContext, so the page won't get stuck DataContext = App.ChatLogViewModel; //and finally the resetting PageInformation info = e.Parameter as PageInformation; currentPartner = info.partner; myChatUser = info.myChatUser; ui_chatlogheader.Text = String.Format("Chatting with {0}", info.nickname); }
public PageInformation(RemoteReference partner, string nickname, ChatUser chatUser) { this.partner = partner; this.nickname = nickname; this.myChatUser = chatUser; }
public MainPage() { this.InitializeComponent(); UIDispatcher = (Windows.UI.Core.DispatchedHandler a) => this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, a); this.chatServiceTag = new TypeTag("chat"); MyChatUsersViewModel = (ChatUsersViewModel)Resources["ChatUsersViewModel"]; this.chatUsers = new Dictionary<Guid, RemoteReference>(); // Set up our own name string nickname = "User" + new Random().Next(1, 99); ui_nickname.Text = nickname; ui_nickname.IsEnabled = false; // Set up our own user and all callbacks myChatUser = new ChatUser(nickname, this.UIDispatcher); myChatUser.PartnerLeftChatEvent += PartnerLeftChat; myChatUser.InviteReceivedEvent += InviteReceivedFromUser; myChatUser.AcceptInviteEvent += AcceptInviteByUser; myChatUser.RejectInviteEvent += RejectInviteByUser; myChatUser.InviteAcceptedEvent += InviteAcceptedByUser; myChatUser.InviteRejectedEvent += InviteRejectedByUser; // Set up the listener callbacks for joining/leaving of users this.userListener = new ServiceListener<RemoteReference>(); userListener.IsDiscovered += UserListener_IsDiscovered; userListener.IsDisconnected += UserListener_IsDisconnected; userListener.IsReconnected += UserListener_IsDiscovered; EventLoop.Instance.Whenever(chatServiceTag, userListener); // Export our service myServicePublication = EventLoop.Instance.Broadcast(chatServiceTag, myChatUser); // Go online on the network NetPOC.Network.NetworkControl.Network networkObj = EventLoop.Instance.GoOnline(); }