async void TripsLoaded(object sender, RoutedEventArgs e)
        {
            var list = (ListViewBase)sender;
            var item = TripData.FromId(defaultId);

            if (item != null)
            {
                // Perform a connected animation to make the page transition smoother.
                list.ScrollIntoView(item);
                var animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("drillout");
                if (animation != null)
                {
                    await list.TryStartConnectedAnimationAsync(animation, item, "MainTile");
                }
            }
        }
示例#2
0
        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;
            }
        }