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); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { // Handle the events from the Back button, but do not show it. systemNavigationManager = SystemNavigationManager.GetForCurrentView(); systemNavigationManager.BackRequested += OnBackRequested; // Parse the URI query parameters. They tell us what to load. var decoder = new WwwFormUrlDecoder((string)e.Parameter); Trip = TripData.FromId(GetDecoderField(decoder, "id")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Trip")); if (Trip == null) { // Invalid trip. return; } if (!int.TryParse(GetDecoderField(decoder, "todo"), out previousSelectedIndex)) { previousSelectedIndex = -1; } // If applicable, perform a connected animation to make the page transition smoother. var animationService = ConnectedAnimationService.GetForCurrentView(); var animation = animationService.GetAnimation("drillin"); if (animation != null) { animation.TryStart(HeroGrid); } // Update the title of the view to match the trip the user is looking at. ApplicationView.GetForCurrentView().Title = Trip.Title; // Generate a UserActivity that says that the user is looking at this trip. var channel = UserActivityChannel.GetDefault(); string activityId = $"trip?id={Trip.Id}"; var activity = await channel.GetOrCreateUserActivityAsync(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 = Trip.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(Trip.Description)); var adaptiveCardJson = card.ToJson(); // Turn the JSON into an adaptive card and set it on the activity. activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(adaptiveCardJson); // Save it to the activity feed. await activity.SaveAsync(); // Start a session. This tels the system know that the user is engaged in the activity right now. this.activitySession = activity.CreateSession(); // Subscribe to the UserActivityRequested event if the system supports it. if (ApiInformation.IsEventPresent(typeof(UserActivityRequestManager).FullName, "UserActivityRequested")) { activityRequestManager = UserActivityRequestManager.GetForCurrentView(); activityRequestManager.UserActivityRequested += OnUserActivityRequested; } }
private async void Window_SourceInitialized(object sender, EventArgs e) { Title = Book.Title; var scrollViewer = FindScrollViewer(ReaderElement); scrollViewer.ScrollToVerticalOffset(PreviousScrollProgress * scrollViewer.ScrollableHeight); var windowHandle = (new System.Windows.Interop.WindowInteropHelper(this)).Handle; // Set custom tab colors. ApplicationViewTitleBar titleBar = ComInterop.GetTitleBarForWindow(windowHandle); if (titleBar != null) { titleBar.BackgroundColor = Color.FromArgb(255, 54, 60, 116); titleBar.ForegroundColor = Color.FromArgb(255, 232, 211, 162); } // Apply grouping behavior. if (!WantsCustomGroupingBehavior) { // Allow caller-specified default grouping to happen. } else if (AssociatedWindow == IntPtr.Zero) { // Open in new group. int preference = DWMTGP_NEW_TAB_GROUP; DwmSetWindowAttribute(windowHandle, DWMWA_TAB_GROUPING_PREFERENCE, ref preference, Marshal.SizeOf <int>()); } else { // Join an existing group. int preference = DWMTGP_TAB_WITH_ASSOCIATED_WINDOW; DwmSetWindowAttribute(windowHandle, DWMWA_TAB_GROUPING_PREFERENCE, ref preference, Marshal.SizeOf <int>()); DwmSetWindowAttribute(windowHandle, DWMWA_ASSOCIATED_WINDOW, ref AssociatedWindow, IntPtr.Size); } // Generate a UserActivity that says that // the user is reading this book. var channel = UserActivityChannel.GetDefault(); var activity = await channel.GetOrCreateUserActivityAsync(BookId); activity.ActivationUri = new Uri($"{App.ProtocolScheme}:{BookId}"); activity.VisualElements.DisplayText = Book.Title; 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()); await activity.SaveAsync(); Session = activity.CreateSessionForWindow(windowHandle); // Listen for user activity requests. userActivityRequestManager = ComInterop.GetUserActivityRequestManagerForWindow(windowHandle); if (userActivityRequestManager != null) { userActivityRequestManager.UserActivityRequested += OnUserActivityRequested; } }