Exemplo n.º 1
0
        private static TabItem AnimationsTab()
        {
            Border border1;
            Border border2;
            RotateTransform rotate;
            Button button1;

            var result = new TabItem
            {
                Header = "Animations",
                Content = new Grid
                {
                    ColumnDefinitions = new ColumnDefinitions
                    {
                        new ColumnDefinition(1, GridUnitType.Star),
                        new ColumnDefinition(1, GridUnitType.Star),
                    },
                    RowDefinitions = new RowDefinitions
                    {
                        new RowDefinition(1, GridUnitType.Star),
                        new RowDefinition(GridLength.Auto),
                    },
                    Children = new Controls
                    {
                        (border1 = new Border
                        {
                            Width = 100,
                            Height = 100,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment = VerticalAlignment.Center,
                            Background = Brushes.Crimson,
                            RenderTransform = new RotateTransform(),
                            Child = new TextBox
                            {
                                Background = Brushes.White,
                                Text = "Hello!",
                                HorizontalAlignment = HorizontalAlignment.Center,
                                VerticalAlignment = VerticalAlignment.Center,
                            },
                        }),
                        (border2 = new Border
                        {
                            Width = 100,
                            Height = 100,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment = VerticalAlignment.Center,
                            Background = Brushes.Coral,
                            Child = new Image
                            {
                                Source = new Bitmap("github_icon.png"),
                                HorizontalAlignment = HorizontalAlignment.Center,
                                VerticalAlignment = VerticalAlignment.Center,
                            },
                            RenderTransform = (rotate = new RotateTransform
                            {
                                PropertyTransitions = new PropertyTransitions
                                {
                                    RotateTransform.AngleProperty.Transition(500),
                                }
                            }),
                            PropertyTransitions = new PropertyTransitions
                            {
                                Layoutable.WidthProperty.Transition(300),
                                Layoutable.HeightProperty.Transition(1000),
                            },
                            [Grid.ColumnProperty] = 1,
                        }),
                        (button1 = new Button
                        {
                            HorizontalAlignment = HorizontalAlignment.Center,
                            Content = "Animate",
                            [Grid.ColumnProperty] = 1,
                            [Grid.RowProperty] = 1,
                        }),
                    },
                },
            };

            button1.Click += (s, e) =>
            {
                if (border2.Width == 100)
                {
                    border2.Width = border2.Height = 400;
                    rotate.Angle = 180;
                }
                else
                {
                    border2.Width = border2.Height = 100;
                    rotate.Angle = 0;
                }
            };

            var start = Animate.Stopwatch.Elapsed;
            var degrees = Animate.Timer
                .Select(x =>
                {
                    var elapsed = (x - start).TotalSeconds;
                    var cycles = elapsed / 4;
                    var progress = cycles % 1;
                    return 360.0 * progress;
                });

            border1.RenderTransform.Bind(
                RotateTransform.AngleProperty,
                degrees,
                BindingPriority.Animation);

            return result;
        }
Exemplo n.º 2
0
        private static TabItem AnimationsTab()
        {
            Border border1;
            Border border2;
            RotateTransform rotate;
            Button button1;

            var result = new TabItem
            {
                Header = "Animations",
                Content = new StackPanel
                {
                    Orientation = Orientation.Vertical,
                    Gap = 4,
                    Margin = new Thickness(10),
                    Children = new Controls
                    {
                        new TextBlock
                        {
                            Text = "Animations",
                            FontWeight = FontWeight.Medium,
                            FontSize = 20,
                            Foreground = SolidColorBrush.Parse("#212121"),
                        },
                        new TextBlock
                        {
                            Text = "A few animations showcased below",
                            FontSize = 13,
                            Foreground = SolidColorBrush.Parse("#727272"),
                            Margin = new Thickness(0, 0, 0, 10)
                        },
                        (button1 = new Button
                        {
                            Content = "Animate",
                            Width = 120,
                            [Grid.ColumnProperty] = 1,
                            [Grid.RowProperty] = 1,
                        }),
                        new Canvas
                        {
                            ClipToBounds = false,
                            Children = new Controls
                            {
                                (border1 = new Border
                                {
                                    Width = 100,
                                    Height = 100,
                                    HorizontalAlignment = HorizontalAlignment.Center,
                                    VerticalAlignment = VerticalAlignment.Center,
                                    Background = Brushes.Crimson,
                                    RenderTransform = new RotateTransform(),
                                    Child = new Grid
                                    {
                                        Children = new Controls
                                        {
                                            new Ellipse()
                                            {
                                                Width = 100,
                                                Height = 100,
                                                Fill =
                                                    new RadialGradientBrush()
                                                    {
                                                        GradientStops =
                                                        {
                                                            new GradientStop(Colors.Blue, 0),
                                                            new GradientStop(Colors.Green, 1)
                                                        },
                                                        Radius = 75
                                                    }
                                            },
                                            new Perspex.Controls.Shapes.Path
                                            {
                                                Data =
                                                    StreamGeometry.Parse(
                                                        "F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"),
                                                Fill =
                                                    new LinearGradientBrush()
                                                    {
                                                        GradientStops =
                                                        {
                                                            new GradientStop(Colors.Green, 0),
                                                            new GradientStop(Colors.LightSeaGreen, 1)
                                                        }
                                                    },
                                                HorizontalAlignment = HorizontalAlignment.Center,
                                                VerticalAlignment = VerticalAlignment.Center,
                                                RenderTransform = new MatrixTransform(Matrix.CreateScale(2, 2))
                                            }
                                        }
                                    },
                                    [Canvas.LeftProperty] = 100,
                                    [Canvas.TopProperty] = 100,
                                }),
                                (border2 = new Border
                                {
                                    Width = 100,
                                    Height = 100,
                                    HorizontalAlignment = HorizontalAlignment.Center,
                                    VerticalAlignment = VerticalAlignment.Center,
                                    Background = Brushes.Coral,
                                    Child = new Image
                                    {
                                        Source = new Bitmap(GetImage("github_icon.png")),
                                        HorizontalAlignment = HorizontalAlignment.Center,
                                        VerticalAlignment = VerticalAlignment.Center,
                                    },
                                    RenderTransform = (rotate = new RotateTransform
                                    {
                                        PropertyTransitions = new PropertyTransitions
                                        {
                                            RotateTransform.AngleProperty.Transition(500),
                                        }
                                    }),
                                    PropertyTransitions = new PropertyTransitions
                                    {
                                        Layoutable.WidthProperty.Transition(300),
                                        Layoutable.HeightProperty.Transition(1000),
                                    },
                                    [Canvas.LeftProperty] = 400,
                                    [Canvas.TopProperty] = 100,
                                }),
                            }
                        }
                    },
                },
            };

            button1.Click += (s, e) =>
            {
                if (border2.Width == 100)
                {
                    border2.Width = border2.Height = 400;
                    rotate.Angle = 180;
                }
                else
                {
                    border2.Width = border2.Height = 100;
                    rotate.Angle = 0;
                }
            };

            var start = Animate.Stopwatch.Elapsed;
            var degrees = Animate.Timer
                .Select(x =>
                {
                    var elapsed = (x - start).TotalSeconds;
                    var cycles = elapsed / 4;
                    var progress = cycles % 1;
                    return 360.0 * progress;
                });

            border1.RenderTransform.Bind(
                RotateTransform.AngleProperty,
                degrees,
                BindingPriority.Animation);

            return result;
        }
Exemplo n.º 3
0
        private static TabItem AnimationsTab()
        {
            Border border1;
            Border border2;
            RotateTransform rotate;
            Button button1;

            var result = new TabItem
            {
                Header = "Animations",
                Content = new StackPanel
                {
					Orientation = Orientation.Vertical,
					Gap = 4,
					Margin = new Thickness(10),
                    Children = new Controls
                    {
						new TextBlock
						{
							Text = "Animations",
							FontWeight = FontWeight.Medium,
							FontSize = 20,
							Foreground = SolidColorBrush.Parse("#212121"),
						},
						new TextBlock
						{
							Text = "A few animations showcased below",
							FontSize = 13,
							Foreground = SolidColorBrush.Parse("#727272"),
							Margin = new Thickness(0, 0, 0, 10)
						},
						(button1 = new Button
						{
							Content = "Animate",
							Width = 120,
							[Grid.ColumnProperty] = 1,
							[Grid.RowProperty] = 1,
						}),
						new Canvas 
						{
                            ClipToBounds = false,
							Children = new Controls 
							{
								(border1 = new Border
								{
									Width = 100,
									Height = 100,
									HorizontalAlignment = HorizontalAlignment.Center,
									VerticalAlignment = VerticalAlignment.Center,
									Background = Brushes.Crimson,
									RenderTransform = new RotateTransform(),
									Child = new TextBox
									{
										Background = Brushes.White,
										Text = "Hello!",
										HorizontalAlignment = HorizontalAlignment.Center,
										VerticalAlignment = VerticalAlignment.Center,
									},
									[Canvas.LeftProperty] = 100,
									[Canvas.TopProperty] = 100,
								}),
								(border2 = new Border
								{
									Width = 100,
									Height = 100,
									HorizontalAlignment = HorizontalAlignment.Center,
									VerticalAlignment = VerticalAlignment.Center,
									Background = Brushes.Coral,
									Child = new Image
									{
										Source = new Bitmap("github_icon.png"),
										HorizontalAlignment = HorizontalAlignment.Center,
										VerticalAlignment = VerticalAlignment.Center,
									},
									RenderTransform = (rotate = new RotateTransform
									{
										PropertyTransitions = new PropertyTransitions
										{
											RotateTransform.AngleProperty.Transition(500),
										}
									}),
									PropertyTransitions = new PropertyTransitions
									{
										Layoutable.WidthProperty.Transition(300),
										Layoutable.HeightProperty.Transition(1000),
									},
									[Canvas.LeftProperty] = 400,
									[Canvas.TopProperty] = 100,
								}),
							}
						}
                    },
                },
            };

            button1.Click += (s, e) =>
            {
                if (border2.Width == 100)
                {
                    border2.Width = border2.Height = 400;
                    rotate.Angle = 180;
                }
                else
                {
                    border2.Width = border2.Height = 100;
                    rotate.Angle = 0;
                }
            };

            var start = Animate.Stopwatch.Elapsed;
            var degrees = Animate.Timer
                .Select(x =>
                {
                    var elapsed = (x - start).TotalSeconds;
                    var cycles = elapsed / 4;
                    var progress = cycles % 1;
                    return 360.0 * progress;
                });

            border1.RenderTransform.Bind(
                RotateTransform.AngleProperty,
                degrees,
                BindingPriority.Animation);

            return result;
        }