private async void InitialImageConnectionStateChanged(Windows.Media.PlayTo.PlayToConnection sender,
                                                              Windows.Media.PlayTo.PlayToConnectionStateChangedEventArgs e)
        {
            if (e.CurrentState == Windows.Media.PlayTo.PlayToConnectionState.Connected)
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                          async() =>
                {
                    // Clear any existing timeout.
                    if (timer != null)
                    {
                        timer.Stop();
                    }

                    // Clear the slide show panel.
                    SlideShowPanel.Children.Clear();

                    // Set the slide show objects and values to show that we are streaming.
                    streaming = true;
                    DisconnectButton.Visibility  = Visibility.Visible;
                    InstructionsBlock.Visibility = Visibility.Collapsed;

                    // Queue and display the next image.
                    var image = await QueueImage(currentImage, true);
                    initialImage.PlayToSource.Next = image.PlayToSource;
                    initialImage.PlayToSource.PlayNext();
                });
            }
            ;
        }
 private void playToConnectionStageChanged(
     Windows.Media.PlayTo.PlayToConnection connection,
     Windows.Media.PlayTo.PlayToConnectionStateChangedEventArgs e)
 {
     messageBlock.Text += "StateChanged: PreviousState = " + e.PreviousState.ToString() + "\n";
     messageBlock.Text += "StateChanged: CurrentState = " + e.CurrentState.ToString() + "\n";
 }
 private void playToConnectionTransferred(
     Windows.Media.PlayTo.PlayToConnection connection,
     Windows.Media.PlayTo.PlayToConnectionTransferredEventArgs e)
 {
     messageBlock.Text += "Transferred: PreviousSource = " + e.PreviousSource.ToString() + "\n";
     messageBlock.Text += "Transferred: CurrentSource = " + e.CurrentSource.ToString() + "\n";
 }
        private void playToConnectionError(
            Windows.Media.PlayTo.PlayToConnection connection,
            Windows.Media.PlayTo.PlayToConnectionErrorEventArgs e)
        {
            if (e.Code == Windows.Media.PlayTo.PlayToConnectionError.DeviceError ||
                e.Code == Windows.Media.PlayTo.PlayToConnectionError.DeviceNotResponding)
            {
                messageBlock.Text += "Error occurred. Disconnecting.\n";
            }

            messageBlock.Text += "Error: Message = " + e.Message.ToString() + "\n";
        }