private async void Window_SourceInitialized(object sender, EventArgs e)
        {
            windowHandle = (new System.Windows.Interop.WindowInteropHelper(this)).Handle;

            // Title bar 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);
            }

            // Generate a UserActivity that says that
            // the user is looking at the library.
            var    channel    = UserActivityChannel.GetDefault();
            string activityId = "home";
            var    activity   = await channel.GetOrCreateUserActivityAsync(activityId);

            // Describe the activity.
            activity.ActivationUri = new Uri($"{App.ProtocolScheme}:{activityId}");
            activity.VisualElements.DisplayText = "Library";
            activity.VisualElements.Description = "4 books";

            var card = new AdaptiveCard();

            // Photo by Mikhail Pavstyuk (https://unsplash.com/photos/EKy2OTRPXdw) free for commercial use.
            card.BackgroundImage = new Uri("https://images.unsplash.com/photo-1423592707957-3b212afa6733");
            card.Body.Add(new AdaptiveTextBlock("Library")
            {
                Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder
            });
            card.Body.Add(new AdaptiveTextBlock("4 books"));
            activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(card.ToJson());

            // Save it to the channel.
            await activity.SaveAsync();

            // Start a session.
            session = activity.CreateSessionForWindow(windowHandle);
        }
        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;
            }
        }