共用方式為


StatusChangedEventArgs 類別

定義

提供 StatusChanged 事件的資訊。

public ref class StatusChangedEventArgs sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class StatusChangedEventArgs final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class StatusChangedEventArgs
Public NotInheritable Class StatusChangedEventArgs
繼承
Object Platform::Object IInspectable StatusChangedEventArgs
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
應用程式功能
location ID_CAP_LOCATION [Windows Phone]

範例

此程式碼範例示範如何處理 StatusChanged 事件。 Geolocator 物件會觸發 StatusChanged 事件,以指出使用者的位置設定已變更。 該事件會透過引數的 Status 屬性 (類型為 PositionStatus) 傳遞對應的狀態。 請注意,此方法並不是從 UI 執行緒呼叫,且 Dispatcher 物件會叫用 UI 變更。 如需詳細資訊,請參閱取得目前位置

using Windows.UI.Core;
...
async private void OnStatusChanged(Geolocator sender, StatusChangedEventArgs e)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        // Show the location setting message only if status is disabled.
        LocationDisabledMessage.Visibility = Visibility.Collapsed;

        switch (e.Status)
        {
            case PositionStatus.Ready:
                // Location platform is providing valid data.

                // notify user: Location platform is ready
                break;

            case PositionStatus.Initializing:
                // Location platform is attempting to acquire a fix. 

                // notify user: Location platform is attempting to obtain a position
                break;

            case PositionStatus.NoData:
                // Location platform could not obtain location data.

                // notify user: Not able to determine the location
                break;

            case PositionStatus.Disabled:
                // The permission to access location data is denied by the user or other policies.

                // notify user: Access to location is denied

                // Clear cached location data if any
                break;

            case PositionStatus.NotInitialized:
                // The location platform is not initialized. This indicates that the application 
                // has not made a request for location data.

                // notify user: No request for location is made yet
                break;

            case PositionStatus.NotAvailable:
                // The location platform is not available on this version of the OS.

                // notify user: Location is not available on this version of the OS
                break;

            default:
                // unknown case
                break;
        }
    });
}

備註

這個物件是傳遞至 StatusChanged 事件的處理常式的引數。

屬性

Status

Geolocator物件的更新狀態。

適用於

另請參閱