void OnUserActivityRequested(UserActivityRequestManager sender, UserActivityRequestedEventArgs e) { using (e.GetDeferral()) { // Generate a user activity that remembers the scroll position. var scrollViewer = FindScrollViewer(ReaderElement); var scrollProgress = scrollViewer.ScrollableHeight > 0 ? scrollViewer.ContentVerticalOffset / scrollViewer.ScrollableHeight : 0.0; // Create user activity session for this window. var activityId = FormattableString.Invariant($"book?id={BookId}&pos={scrollProgress}"); var activity = new UserActivity(activityId); activity.ActivationUri = new Uri($"{App.ProtocolScheme}:{activityId}"); activity.VisualElements.DisplayText = Book.Title; activity.VisualElements.Description = $"{(int)(scrollProgress * 100)}% complete"; var card = new AdaptiveCard(); card.BackgroundImage = Book.ImageUri; card.Body.Add(new AdaptiveTextBlock(Book.Title) { Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }); activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(card.ToJson()); e.Request.SetUserActivity(activity); } }
void OnUserActivityRequested(UserActivityRequestManager sender, UserActivityRequestedEventArgs e) { // The system raises the UserActivityRequested event to request that the // app generate an activity that describes what the user is doing right now. // This activity is used to restore the app as part of a Set. using (e.GetDeferral()) { // Determine which trip and to-do item the user is currently working on. var description = Trip.Description; var index = ToDoListView.SelectedIndex; if (index >= 0) { description = ToDoListView.SelectedItem.ToString(); } // Generate a UserActivity that says that the user is looking at // a particular to-do item on this trip. string activityId = $"trip?id={Trip.Id}&todo={index}"; var activity = new UserActivity(activityId); // The system uses this URI to resume the activity. activity.ActivationUri = new Uri($"{App.ProtocolScheme}:{activityId}"); // Describe the activity. activity.VisualElements.DisplayText = Trip.Title; activity.VisualElements.Description = description; // Build the adaptive card JSON with the helper classes in the NuGet package. // You are welcome to generate your JSON using any library you like. var card = new AdaptiveCard(); card.BackgroundImage = Trip.ImageSourceUri; card.Body.Add(new AdaptiveTextBlock(Trip.Title) { Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }); card.Body.Add(new AdaptiveTextBlock(description)); var adaptiveCardJson = card.ToJson(); // Turn the JSON into an adaptive card and set it on the activity. activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(adaptiveCardJson); // Respond to the request. e.Request.SetUserActivity(activity); } }