Skip to content

Latest commit

 

History

History
87 lines (62 loc) · 3.8 KB

appnotificationprogressbar_bindstatus_1678798282.md

File metadata and controls

87 lines (62 loc) · 3.8 KB
-api-id -api-type
M:Microsoft.Windows.AppNotifications.Builder.AppNotificationProgressBar.BindStatus
winrt method

Microsoft.Windows.AppNotifications.Builder.AppNotificationProgressBar.BindStatus

-description

Binds the AppNotificationProgressBar.Status property.

-returns

Returns the AppNotificationProgressBar instance so that additional method calls can be chained.

-remarks

The Status value is bound by default. Update the bound status value by assigning an AppNotificationProgressData object to the AppNotification.Progresss property.

You can also set the status with the AppNotificationProgressBar.Status property or by calling AppNotificationProgressBar.SetStatus.

For guidance on using the AppNotificationBuilder APIs to create the UI for app notifications, see App notification content.

For reference information about the XML schema for app notifications, see App notification content schema.

-see-also

-examples

The following example illustrates how to set the Status property of an app notification progress bar using data binding.

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);

The resulting XML payload:

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

Update the bound values by calling AppNotificationManager.UpdateAsync and specifying the tag, and optionally the group, of the tag you want to update.

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);
}