Professional: Windows® 8 Programming by Nick Lecrenski & Doug Holland & Allen Sanders & Kevin Ashley

Professional: Windows® 8 Programming by Nick Lecrenski & Doug Holland & Allen Sanders & Kevin Ashley

Author:Nick Lecrenski & Doug Holland & Allen Sanders & Kevin Ashley
Language: eng
Format: epub
Publisher: John Wiley & Sons
Published: 2012-12-04T16:00:00+00:00


2. Launch the Data Samples on both PCs with proximity initiated, and bring the apps to the foreground.

3. Click the Proximity example on both PCs, select the Subscribe for Messages option on one, and the Publish Message option on another, and you should publish and receive a message. Figure 6-8 shows the screen of the receiving PC with a Hello World message transmitted and received via proximity. FIGURE 6-8

Listing 6-17 shows the ProximityDemo.xaml.cs code-behind file with publishing and receiving messages via PublishMessage and SubscribeForMessage methods of ProximityDevice type.

LISTING 6-17: ProximityDemo.xaml.cs

private void send_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (Message.Text.Length > 0) { _publishedMessage = _proximityDevice .PublishMessage("Windows.SampleMessageType", Message.Text); log.Items.Add("Published, tap another device to transmit."); } else { Message.Text = "Type a message"; } } private void subscribe_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { _receivedMessage = _proximityDevice .SubscribeForMessage("Windows.SampleMessageType", OnMessageReceived); log.Items.Add( "Subscribed, enter proximity to receive" ); } void OnMessageReceived(ProximityDevice proximityDevice, ProximityMessage message) { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { log.Items.Add( String.Format("Message received: {0}", message.DataAsString)); }); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.