AppNotificationProgressBar 类

定义

表示在应用通知上显示的进度栏。

public ref class AppNotificationProgressBar sealed
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilderContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilderContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class AppNotificationProgressBar final
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilderContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilderContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class AppNotificationProgressBar
function AppNotificationProgressBar()
Public NotInheritable Class AppNotificationProgressBar
继承
Object Platform::Object IInspectable AppNotificationProgressBar
属性

示例

以下示例演示如何将进度栏添加到应用通知的 XML 有效负载。

var notification = new AppNotificationBuilder()
    .AddText("Downloading your weekly playlist...")
    .AddProgressBar(new AppNotificationProgressBar()
        .BindTitle()
        .BindStatus()
        .BindValue()
        .BindValueStringOverride())
        .SetTag(tagName)
        .SetGroup(groupName))
    .BuildNotification();

var data = new AppNotificationProgressData (sequenceNumber /* Sequence number */);
data.Title = "Retreiving files"; // Binds to {progressTitle} in xml payload
data.Value = (double) currentFile / totalFiles; // Binds to {progressValue} in xml payload
data.ValueStringOverride = String.Format("{0}/{1} files", currentFile, totalFiles); // Binds to {progressValueString} in xml payload
data.Status = "Downloading..."; // Binds to {progressStatus} in xml payload

notification.Progress = data;

AppNotificationManager.Default.Show(notification);

生成的 XML 有效负载:

<toast>
    <visual>
        <binding template='ToastGeneric'>
            <text>Downloading your weekly playlist...</text>
            <progress title='{progressTitle}' status='{progressStatus}' value='{progressValue}' valueStringOverride='{progressValueString}'/>
        </binding>
    </visual>
</toast>

通过调用 AppNotificationManager.UpdateAsync 并指定要更新的标记(可选)组来更新绑定值。

private async Task UpdateProgressBar()
{
    var data = new AppNotificationProgressData(sequenceNumber /* Sequence number */);
    data.Title = "Retreiving files"; // Binds to {progressTitle} in xml payload
    data.Value = (double)currentFile / totalFiles; // Binds to {progressValue} in xml payload
    data.ValueStringOverride = String.Format("{0}/{1} files", currentFile, totalFiles); // Binds to {progressValueString} in xml payload
    data.Status = (currentFile < totalFiles) ? "Downloading..." : "Complete!"; // Binds to {progressStatus} in xml payload

    await AppNotificationManager.Default.UpdateAsync(data, tagName, groupName);
}

注解

以下屏幕截图显示了带有进度栏的应用通知。

带有进度栏的应用通知的屏幕截图。

通过调用 AppNotificationBuilder.AddProgressBar,将进度栏添加到应用通知的 XML 有效负载。

有关使用 AppNotificationBuilder API 创建应用通知 UI 的指导,请参阅 应用通知内容

有关应用通知的 XML 架构的参考信息,请参阅 应用通知内容架构

构造函数

AppNotificationProgressBar()

初始化 AppNotificationProgressBar 类的新实例。

属性

Status

获取或设置应用通知进度栏的状态文本。

Title

获取或设置应用通知进度栏的标题文本。

Value

获取或设置应用通知进度栏的进度值。

ValueStringOverride

获取或设置应用通知进度栏的值字符串替代。

方法

BindStatus()

绑定 AppNotificationProgressBar.Status 属性。

BindTitle()

绑定 AppNotificationProgressBar.Title 属性。

BindValue()

绑定 AppNotificationProgressBar.Value 属性。

BindValueStringOverride()

绑定 AppNotificationProgressBar.ValueStringOverride 属性。

SetStatus(String)

设置应用通知进度栏的状态文本。

SetTitle(String)

设置应用通知进度栏的标题文本。

SetValue(Double)

设置应用通知进度栏的进度值。

SetValueStringOverride(String)

设置应用通知进度栏的值字符串替代。

适用于