コード例 #1
0
        private void MoreInfoClicked(object sender, RoutedEventArgs e)
        {
            if (_moreInfoContent == null)
            {
                return;
            }

            var button = (Button)sender;
            var sample = button.DataContext as Sample;

            var container = button.FindAscendant <GridViewItem>();

            if (container == null)
            {
                return;
            }

            var point = container.TransformToVisual(this).TransformPoint(new Windows.Foundation.Point(0, 0));

            var x = point.X - ((_moreInfoContent.Width - container.ActualWidth) / 2);
            var y = point.Y - ((_moreInfoContent.Height - container.ActualHeight) / 2);

            x = Math.Max(x, 10);
            x = Math.Min(x, ActualWidth - _moreInfoContent.Width - 10);

            y = Math.Max(y, 10);
            y = Math.Min(y, ActualHeight - _moreInfoContent.Height - 10);

            Canvas.SetLeft(_moreInfoContent, x);
            Canvas.SetTop(_moreInfoContent, y);

            var centerX = (point.X + (container.ActualWidth / 2)) - x;
            var centerY = (point.Y + (container.ActualHeight / 2)) - y;

            VisualExtensions.SetCenterPoint(_moreInfoContent, new Vector3((float)centerX, (float)centerY, 0).ToString());

            // _samplePickerGridView.PrepareConnectedAnimation("sample_icon", sample, "SampleIcon");
            _moreInfoContent.DataContext = sample;
            _moreInfoCanvas.Visibility   = Visibility.Visible;

            // var animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("sample_icon");
            // var result = animation.TryStart(_moreInfoImage);
        }
コード例 #2
0
        private void ShowTextShimmingAsync()
        {
            var width = 1920;

            _redLight   = CreatePointLightAndStartAnimation(_redColor, -width * 1, width * 2);
            _blueLight  = CreatePointLightAndStartAnimation(_blueColor, width * 2, -width * 1);
            _greenLight = CreateAmbientLightAndStartAnimation();
            var focusVisual = VisualExtensions.GetVisual(FocusPanel);
            var relayVisual = VisualExtensions.GetVisual(RelaxPanel);

            _redLight.Targets.Add(focusVisual);
            _blueLight.Targets.Add(focusVisual);

            _redLight.Targets.Add(relayVisual);
            _blueLight.Targets.Add(relayVisual);

            _greenLight.Targets.Add(focusVisual);
            _greenLight.Targets.Add(relayVisual);
        }
コード例 #3
0
        private void ShowTextShimming()
        {
            var compositor  = Window.Current.Compositor;
            var titleVisual = VisualExtensions.GetVisual(Title);
            var pointLight  = compositor.CreatePointLight();

            pointLight.Color           = Colors.White;
            pointLight.CoordinateSpace = titleVisual;
            pointLight.Targets.Add(titleVisual);
            pointLight.Offset = new Vector3(-(float)Title.ActualWidth * 5, (float)Title.ActualHeight / 2, 100.0f);

            var offsetAnimation = compositor.CreateScalarKeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(1.0f, (float)Title.ActualWidth * 5, compositor.CreateLinearEasingFunction());
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(5000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            pointLight.StartAnimation("Offset.X", offsetAnimation);
        }
コード例 #4
0
        private void HideBackgroundLight()
        {
            if (_backgroundLight == null)
            {
                return;
            }

            var compositor = Window.Current.Compositor;

            var scalarAnimation = compositor.CreateScalarKeyFrameAnimation();

            scalarAnimation.InsertKeyFrame(1.0f, 0, compositor.CreateLinearEasingFunction());
            scalarAnimation.Duration = TimeSpan.FromSeconds(1);
            _backgroundLight.StartAnimation(nameof(AmbientLight.Intensity), scalarAnimation);
            _buttonLight.StartAnimation(nameof(AmbientLight.Intensity), scalarAnimation);

            var footBackgroundVisual = VisualExtensions.GetVisual(FootBackground);

            footBackgroundVisual.StartAnimation(nameof(footBackgroundVisual.Opacity), scalarAnimation);
        }
コード例 #5
0
        private void CreateBackgroundLight()
        {
            var compositor   = Window.Current.Compositor;
            var buttonVisual = VisualExtensions.GetVisual(ButtonPanel);
            var focusVisual  = VisualExtensions.GetVisual(FocusPanel);
            var relayVisual  = VisualExtensions.GetVisual(RelaxPanel);
            var footVisual   = VisualExtensions.GetVisual(FootBackground);

            _backgroundLight           = compositor.CreateAmbientLight();
            _backgroundLight.Color     = ViewModel.IsInPomodoro ? _lightRedColor : _lightBlueColor;
            _backgroundLight.Intensity = 0;
            _backgroundLight.Targets.Add(focusVisual);
            _backgroundLight.Targets.Add(relayVisual);
            _backgroundLight.Targets.Add(footVisual);

            _buttonLight           = compositor.CreateAmbientLight();
            _buttonLight.Color     = Colors.White;
            _buttonLight.Intensity = 0;
            _buttonLight.Targets.Add(buttonVisual);
        }
コード例 #6
0
        private PointLight CreatePointLightAndStartAnimation(Color color, float startOffsetX, float endOffsetX, float height)
        {
            var compositor = Window.Current.Compositor;

            var rootVisual = VisualExtensions.GetVisual(Root);
            var pointLight = compositor.CreatePointLight();

            pointLight.Color           = color;
            pointLight.CoordinateSpace = rootVisual;
            pointLight.Offset          = new Vector3(startOffsetX, height, 300.0f);

            var offsetAnimation = compositor.CreateScalarKeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(1.0f, endOffsetX, compositor.CreateLinearEasingFunction());
            offsetAnimation.Duration          = TimeSpan.FromSeconds(10);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            pointLight.StartAnimation("Offset.X", offsetAnimation);
            return(pointLight);
        }
コード例 #7
0
        private AmbientLight CreateAmbientLightAndStartAnimation()
        {
            var compositor = Window.Current.Compositor;

            var rootVisual   = VisualExtensions.GetVisual(Root);
            var ambientLight = compositor.CreateAmbientLight();

            ambientLight.Intensity = 0;
            ambientLight.Color     = _greenColor;

            var offsetAnimation = compositor.CreateScalarKeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0.25f, 0, compositor.CreateLinearEasingFunction());
            offsetAnimation.InsertKeyFrame(0.5f, 0.20f, compositor.CreateLinearEasingFunction());
            offsetAnimation.InsertKeyFrame(0.75f, 0, compositor.CreateLinearEasingFunction());
            offsetAnimation.Duration          = TimeSpan.FromSeconds(10);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            ambientLight.StartAnimation(nameof(AmbientLight.Intensity), offsetAnimation);
            return(ambientLight);
        }
コード例 #8
0
        private void ContainerItem_Loaded(object sender, RoutedEventArgs e)
        {
            var itemsPanel    = (ItemsWrapGrid)SamplePickerGridView.ItemsPanelRoot;
            var itemContainer = (GridViewItem)sender;

            itemContainer.Loaded -= this.ContainerItem_Loaded;

            var button = itemContainer.FindDescendant <Button>();

            if (button != null)
            {
                button.Click     -= MoreInfoClicked;
                button.LostFocus -= MoreInfoLostFocus;
                button.Click     += MoreInfoClicked;
                button.LostFocus += MoreInfoLostFocus;
            }

            var itemIndex = SamplePickerGridView.IndexFromContainer(itemContainer);

            var referenceIndex = itemsPanel.FirstVisibleIndex;

            if (SamplePickerGridView.SelectedIndex >= 0)
            {
                referenceIndex = SamplePickerGridView.SelectedIndex;
            }

            var relativeIndex = Math.Abs(itemIndex - referenceIndex);

            if (itemContainer.Content != CurrentSample && itemIndex >= 0 && itemIndex >= itemsPanel.FirstVisibleIndex && itemIndex <= itemsPanel.LastVisibleIndex)
            {
                var staggerDelay = TimeSpan.FromMilliseconds(relativeIndex * 30);

                VisualExtensions.SetNormalizedCenterPoint(itemContainer, "0.5");

                AnimationBuilder.Create()
                .Opacity(from: 0, to: 1, delay: staggerDelay)
                .Scale(from: 0.9, to: 1, delay: staggerDelay)
                .Start(itemContainer);
            }
        }
コード例 #9
0
        private PointLight CreatePointLightAndStartAnimation(Color color, TimeSpan delay)
        {
            var width      = 1920f;
            var height     = 1050f;
            var compositor = Window.Current.Compositor;
            var rootVisual = VisualExtensions.GetVisual(this);
            var pointLight = compositor.CreatePointLight();

            pointLight.Color           = color;
            pointLight.CoordinateSpace = rootVisual;
            pointLight.Offset          = new Vector3(-width * 3, height / 2, 150.0f);

            var offsetAnimation = compositor.CreateScalarKeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(1.0f, width * 4, compositor.CreateLinearEasingFunction());
            offsetAnimation.Duration          = TimeSpan.FromSeconds(10);
            offsetAnimation.DelayTime         = delay;
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            pointLight.StartAnimation("Offset.X", offsetAnimation);
            return(pointLight);
        }
コード例 #10
0
        private void MoreInfoClicked(object sender, RoutedEventArgs e)
        {
            if (MoreInfoContent == null)
            {
                return;
            }

            var button = (Button)sender;
            var sample = button.DataContext as Sample;

            var container = button.FindAscendant <GridViewItem>();

            if (container == null)
            {
                return;
            }

            var point = container.TransformToVisual(this).TransformPoint(new Windows.Foundation.Point(0, 0));

            var x = point.X - ((MoreInfoContent.Width - container.ActualWidth) / 2);
            var y = point.Y - ((MoreInfoContent.Height - container.ActualHeight) / 2);

            x = Math.Max(x, 10);
            x = Math.Min(x, ActualWidth - MoreInfoContent.Width - 10);

            y = Math.Max(y, 10);
            y = Math.Min(y, ActualHeight - MoreInfoContent.Height - 10);

            Canvas.SetLeft(MoreInfoContent, x);
            Canvas.SetTop(MoreInfoContent, y);

            var centerX = (point.X + (container.ActualWidth / 2)) - x;
            var centerY = (point.Y + (container.ActualHeight / 2)) - y;

            VisualExtensions.SetCenterPoint(MoreInfoContent, new Vector3((float)centerX, (float)centerY, 0).ToString());

            MoreInfoContent.DataContext = sample;
            MoreInfoCanvas.Visibility   = Visibility.Visible;
        }
コード例 #11
0
        private void SetupExpressionAnimationsForCard()
        {
            _cardVisual = VisualExtensions.GetVisual(Card);
            _cardVisual.RelativeSizeAdjustment = Vector2.One;
            _cardVisual.CenterPoint            = new Vector3(Card.RenderSize.ToVector2() / 2, 0.0f);

            var initialPositionY = (float)ActualHeight;

            _cardVisual.Offset = new Vector3(0.0f, initialPositionY, 0.0f);

            _progress.InsertScalar("Progress", 0);
            var progressExpressionNode = _progress.GetReference().GetScalarProperty("Progress");

            // Scale the card visual based on the progress.
            _cardVisual.StartAnimation("Scale", EF.Vector3(1.0f, 1.0f, 1.0f) * EF.Lerp(0.6f, 1.0f, progressExpressionNode));
            // Fade in the card visual based on the progress.
            _cardVisual.StartAnimation("Opacity", EF.Lerp(0.0f, 1.0f, progressExpressionNode));
            // Move the card visual based on the progress.
            var offset = initialPositionY * (1.0f - progressExpressionNode);

            _cardVisual.StartAnimation("Offset.Y", offset);
        }
        public async Task SetAndGetTranslation()
        {
            await App.DispatcherQueue.EnqueueAsync(async() =>
            {
                var button = new Button();
                var grid   = new Grid()
                {
                    Children = { button }
                };

                VisualExtensions.SetTranslation(button, "80, 20, 0");

                await SetTestContentAsync(grid);

                var success = button.GetVisual().Properties.TryGetVector3("Translation", out Vector3 translation);

                Assert.AreEqual(success, CompositionGetValueStatus.Succeeded);
                Assert.AreEqual(translation, new Vector3(80, 20, 0));

                string text = VisualExtensions.GetTranslation(button);

                Assert.AreEqual(text, new Vector3(80, 20, 0).ToString());
            });
        }
コード例 #13
0
        public NotificationDialog()
        {
            InitializeComponent();

            InitializeCardRenderer();

            // Set the initial state.
            VisualStateManager.GoToState(this, "EmptyState", false);

            // Clip the top-level panel so nothing goes outside will be visible.
            VisualExtensions.GetVisual(LayoutRoot).Clip = Window.Current.Compositor.CreateInsetClip();

            Loaded += async(s, e) =>
            {
                if (App.IsDeepLink)
                {
                    return;
                }

                // Simulate a network request so the message dialog will appear after 2.5s.
                await Task.Delay(2500);

                // Show the message dialog on the bottom right of the screen.
                VisualStateManager.GoToState(this, "MinimizedState", true);
            };

            AddDummyAdjusters();

            ShowMapAndPolyline();

            void AddDummyAdjusters()
            {
                Adjusters.Add(new Adjuster("Emma", 7, GenderType.Female));
                Adjusters.Add(new Adjuster("Max", 3.4, GenderType.Male, StatusType.Busy));
                Adjusters.Add(new Adjuster("Charlotte", 1.2, GenderType.Female));
                Adjusters.Add(new Adjuster("Chloe", 8.9, GenderType.Female));
                Adjusters.Add(new Adjuster("Giselle", 15.6, GenderType.Female, StatusType.Busy));
            }

            void ShowMapAndPolyline()
            {
                Map.LoadingStatusChanged += ActivityMapLoadingStatusChanged;

                async void ActivityMapLoadingStatusChanged(MapControl sender, object args)
                {
                    Map.LoadingStatusChanged -= ActivityMapLoadingStatusChanged;

                    await ShowMapContents();

                    async Task ShowMapContents()
                    {
                        var spaceNeedlePoint = new Geopoint(new BasicGeoposition()
                        {
                            Latitude  = 47.6204,
                            Longitude = -122.3491
                        });

                        MapScene spaceNeedleScene = MapScene.CreateFromLocationAndRadius(spaceNeedlePoint,
                                                                                         240,   /* show this many meters around */
                                                                                         45,    /* looking at it to the south east*/
                                                                                         75 /* degrees pitch */);

                        await Map.TrySetSceneAsync(spaceNeedleScene);

                        var ownerAddressPoint = new Button {
                            Style = (Style)App.Current.Resources["ButtonMapPinStyle"]
                        };

                        Map.Children.Add(ownerAddressPoint);
                        MapControl.SetLocation(ownerAddressPoint, new Geopoint(new BasicGeoposition
                        {
                            Latitude  = 47.6204,
                            Longitude = -122.3491
                        }));
                        MapControl.SetNormalizedAnchorPoint(ownerAddressPoint, new Point(0.5, 0.5));

                        var branchPoint1 = new Button {
                            Style = (Style)App.Current.Resources["ButtonMapBuildingStyle"]
                        };

                        Map.Children.Add(branchPoint1);
                        MapControl.SetLocation(branchPoint1, new Geopoint(new BasicGeoposition
                        {
                            Latitude  = 47.6208148,
                            Longitude = -122.350805
                        }));
                        MapControl.SetNormalizedAnchorPoint(branchPoint1, new Point(0.5, 0.5));

                        var branchPoint2 = new Button {
                            Style = (Style)App.Current.Resources["ButtonMapBuildingStyle"]
                        };

                        Map.Children.Add(branchPoint2);
                        MapControl.SetLocation(branchPoint2, new Geopoint(new BasicGeoposition
                        {
                            Latitude  = 47.619535,
                            Longitude = -122.349163
                        }));
                        MapControl.SetNormalizedAnchorPoint(branchPoint2, new Point(0.5, 0.5));
                    }
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Prepares the specified element to display the specified item.
        /// </summary>
        /// <param name="obj">The element that's used to display the specified item.</param>
        /// <param name="item">The item to display.</param>
        protected override void PrepareContainerForItemOverride(DependencyObject obj, object item)
        {
            base.PrepareContainerForItemOverride(obj, item);

            if (!(obj is FrameworkElement element))
            {
                return;
            }

            var heightBinding = new Binding
            {
                Source = this,
                Path   = new PropertyPath(nameof(ItemHeight)),
                Mode   = BindingMode.TwoWay
            };

            var widthBinding = new Binding
            {
                Source = this,
                Path   = new PropertyPath(nameof(ItemWidth)),
                Mode   = BindingMode.TwoWay
            };

            element.SetBinding(HeightProperty, heightBinding);
            element.SetBinding(WidthProperty, widthBinding);

            // First populate our local variable for referencing ItemsWrapGrid for the first time.
            if (!_monitorFirstItemContainerLoadedEvent && _virtualizedPanel == null)
            {
                _virtualizedPanel = ItemsPanelRoot as ItemsWrapGrid;
            }

            // Then decide if we should run the animation.
            if (_virtualizedPanel == null || _isAnimated)
            {
                return;
            }

            Opacity = 0;

            if (!_monitorFirstItemContainerLoadedEvent)
            {
                _monitorFirstItemContainerLoadedEvent = true;

                element.Loaded += OnContainerLoaded;

                // At this point, the index values are all ready to use.
                async void OnContainerLoaded(object sender, RoutedEventArgs e)
                {
                    element.Loaded -= OnContainerLoaded;

                    for (var i = _virtualizedPanel.FirstVisibleIndex; i <= _virtualizedPanel.LastVisibleIndex; i++)
                    {
                        var numberOfColumns = GetNumberOfColumns();
                        var rowIndex        = i % numberOfColumns;
                        var colIndex        = i / numberOfColumns;

                        if (ContainerFromIndex(i) is FrameworkElement container)
                        {
                            container.Opacity = 0;

                            if (_visibleItemContainers.ContainsKey(container))
                            {
                                _visibleItemContainers.Remove(container);
                            }
                            _visibleItemContainers.Add(container, new Position(rowIndex, colIndex));
                        }

                        Opacity = 1;
                    }

                    _isAnimated = true;
                    await Task.Delay(InitialDelay);

                    RunStaggeredDiagonalAnimationOnVisibleItemContainers();

                    void RunStaggeredDiagonalAnimationOnVisibleItemContainers()
                    {
                        var numberOfColumns = GetNumberOfColumns();
                        var numberOfRows    = Math.Ceiling(ActualHeight / ItemHeight);
                        var last            = (numberOfRows - 1) + (numberOfColumns - 1);

                        for (var i = 0; i <= last; i++)
                        {
                            var sum        = i;
                            var containers = _visibleItemContainers.Where(c => c.Value.Row + c.Value.Column == sum).Select(k => k.Key);

                            foreach (var container in containers)
                            {
                                var containerVisual = VisualExtensions.GetVisual(container);
                                _scaleAnimation.DelayTime   = TimeSpan.FromMilliseconds(AnimationDelay * i);
                                containerVisual.CenterPoint = new Vector3((float)ItemWidth, (float)ItemHeight, 0) * 0.5f;
                                containerVisual.StartAnimation(nameof(Visual.Scale), _scaleAnimation);

                                container.Fade(1.0f, AnimationDuration, AnimationDelay * i).Start();
                            }
                        }
                    }
                }
            }
        }