다음을 통해 공유


DeviceArrivedEventHandler 대리자

정의

DeviceArrived 이벤트를 처리하는 메서드에 대해 설명합니다.

public delegate void DeviceArrivedEventHandler(ProximityDevice ^ sender);
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(4020886121, 63201, 18889, 164, 158, 142, 15, 197, 143, 185, 17)]
class DeviceArrivedEventHandler : MulticastDelegate
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(4020886121, 63201, 18889, 164, 158, 142, 15, 197, 143, 185, 17)]
public delegate void DeviceArrivedEventHandler(ProximityDevice sender);
var deviceArrivedEventHandlerHandler = function(sender){
/* Your code */
}
Public Delegate Sub DeviceArrivedEventHandler(sender As ProximityDevice)

매개 변수

sender
ProximityDevice

DeviceArrived 이벤트를 발생시킨 근접 디바이스입니다.

특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)
앱 기능
ID_CAP_PROXIMITY [Windows Phone] proximity ID_CAP_PROXIMITY [Windows Phone]

예제

Windows.Networking.Proximity.ProximityDevice proximityDevice;

private void InitializeProximityDevice()
{
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

    if (proximityDevice != null) {
        proximityDevice.DeviceArrived += ProximityDeviceArrived;
        proximityDevice.DeviceDeparted += ProximityDeviceDeparted;

        WriteMessageText("Proximity device initialized.\n");
    }
    else
    {
        WriteMessageText("Failed to initialized proximity device.\n");
    }
}

private void ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)
{
    WriteMessageText("Proximate device arrived. id = " + device.DeviceId + "\n");
}

private void ProximityDeviceDeparted(Windows.Networking.Proximity.ProximityDevice device)
{
    WriteMessageText("Proximate device departed. id = " + device.DeviceId + "\n");
}

// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher messageDispatcher = Window.Current.CoreWindow.Dispatcher;

async private void WriteMessageText(string message, bool overwrite = false)
{
    await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        () =>
        {
            if (overwrite)
                MessageBlock.Text = message;
            else
                MessageBlock.Text += message;
        });
}
Dim proximityDevice As Windows.Networking.Proximity.ProximityDevice

Private Sub InitializeProximityDevice()

    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice IsNot Nothing Then
        AddHandler proximityDevice.DeviceArrived, AddressOf ProximityDeviceArrived
        AddHandler proximityDevice.DeviceDeparted, AddressOf ProximityDeviceDeparted

        WriteMessageText("Proximity device initialized." & vbTab)
    Else
        WriteMessageText("Failed to initialized proximity device." & vbTab)
    End If
End Sub

Private Sub ProximityDeviceArrived(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device arrived. id = " & device.DeviceId & vbTab)
End Sub

Private Sub ProximityDeviceDeparted(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device departed. id = " & device.DeviceId & vbTab)
End Sub

' Write a message to MessageBlock on the UI thread.
Private Async Sub WriteMessageText(message As String, Optional overwrite As Boolean = False)
    Await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        Sub()
            If overwrite Then
                MessageBlock.Text = message
            Else
                MessageBlock.Text &= message
            End If
        End Sub)
End Sub

적용 대상

추가 정보