ToastOcclusionManagerPreview.SetToastWindowMargin(WindowId, Double) 方法

定义

请求 OS 显示具有指定垂直偏移量(以视图像素为单位)的应用通知,以避免通知遮挡指定窗口中的内容。

重要

ToastOcclusionManagerPreview.SetToastWindowMargin API 是受限访问功能的一部分, (请参阅 LimitedAccessFeatures 类) 。 有关详细信息或请求解锁令牌,请使用 LAF 访问令牌请求表单

public:
 static void SetToastWindowMargin(WindowId appWindowId, double margin);
 static void SetToastWindowMargin(WindowId const& appWindowId, double const& margin);
public static void SetToastWindowMargin(WindowId appWindowId, double margin);
function setToastWindowMargin(appWindowId, margin)
Public Shared Sub SetToastWindowMargin (appWindowId As WindowId, margin As Double)

参数

appWindowId
WindowId

与通知偏移请求关联的窗口的 WindowId 。 若要应用偏移量,必须在主屏幕上最大化指定的窗口,并且屏幕键盘不得可见。

margin
Double

double

显示应用通知的垂直偏移量(以视图像素为单位)。 边距的当前最大值为 180 像素。 对大于 180 像素的边距的请求将成功,但会限制为 180 像素。 如果指定了负值,则会将其固定为 0。

注解

此 API 将作为预览版发布,以便企业客户能够测试该功能。 将来的版本中可能会删除和/或修改此 API。 在使用 API 之前,应用应调用 LimitedAccessFeatures.TryUnlockFeature,传入 Microsoft 提供的功能 ID 和应用令牌,以验证应用是否有权使用该 API。 未经授权的应用的调用将不起作用。

以下示例代码演示如何检查调用应用的 SetToastWindowMargin 的可用性,如果可用,请调用 API 以请求将应用通知向上移动 90 像素。 应在应用启动期间进行这些调用。

// App.xaml.cpp

static Platform::String^ FeatureName = L"com.microsoft.windows.ui.notifications.preview.toastOcclusionManagerPreview";
static Platform::String^ ApiToken = L"[API token]";
static Platform::String^ ApiAttestation = L"[Package family name] has registered their use of com.microsoft.windows.ui.notifications.preview.toastOcclusionManagerPreview with Microsoft and agrees to the terms of use.";


App::App()
{
    InitializeComponent();
    Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);

    m_isToastOcclusionManagerPreviewAvailable = DetectToastOcclusionManagerPreview();
}

bool App::DetectToastOcclusionManagerPreview()
{
    LimitedAccessFeatureRequestResult^ result = LimitedAccessFeatures::TryUnlockFeature(FeatureName, ApiToken, ApiAttestation);
    switch (result->Status)
    {
    case LimitedAccessFeatureStatus::Available:
    case LimitedAccessFeatureStatus::AvailableWithoutToken:
        return true;
    }
    return false;
}

void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
{
    ...

    // Request for toast window to be shifted up 90 pixels
    // Toasts will only be shifted up if the window is maximized,
    // on the primary screen and the software keyboard isn't present. 
    if (!m_isRegistered && m_isToastOcclusionManagerPreviewAvailable)
    {
        HWND window;

        IInspectable* inspectable = reinterpret_cast<IInspectable*>(CoreWindow::GetForCurrentThread());

        winrt::com_ptr<ICoreWindowInterop> interop;

        if (SUCCEEDED(inspectable->QueryInterface(IID_PPV_ARGS(&interop))) && SUCCEEDED(interop->get_WindowHandle(&window)))
        {
            // Get the windowId
            winrt::Windows::UI::WindowId windowId{ reinterpret_cast<uint64_t>(window) };

            ToastOcclusionManagerPreview::SetToastWindowMargin(windowId, 90);
        }

        m_isRegistered = true;
    }
}

适用于

另请参阅