/// <summary> /// The default template for the <see cref="TextBox"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(TextBox control) { Border result = new Border { Name = "border", Padding = new Thickness(2), [~Border.BackgroundProperty] = control[~TextBox.BackgroundProperty], [~Border.BorderBrushProperty] = control[~TextBox.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TextBox.BorderThicknessProperty], Child = new ScrollViewer { [~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty], [~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty], [~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty], Content = new TextPresenter { Name = "textPresenter", [~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty], [~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty], [~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty], [~TextPresenter.TextProperty] = control[~TextBox.TextProperty], [~TextPresenter.TextWrappingProperty] = control[~TextBox.TextWrappingProperty], } } }; return result; }
public void Invalidating_Child_Should_Remeasure_Parent() { var layoutManager = new LayoutManager(); using (PerspexLocator.EnterScope()) { PerspexLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(layoutManager); Border border; StackPanel panel; var root = new TestLayoutRoot { Child = panel = new StackPanel { Children = new Controls.Controls { (border = new Border()) } } }; layoutManager.ExecuteInitialLayoutPass(root); Assert.Equal(new Size(0, 0), root.DesiredSize); border.Width = 100; border.Height = 100; layoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(100, 100), panel.DesiredSize); } }
/// <summary> /// The default template for a <see cref="GridSplitter"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(GridSplitter control) { Border border = new Border { [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], }; return border; }
private Control Template(GridSplitter control) { Border border = new Border { [~Border.BackgroundProperty] = control[~GridSplitter.BackgroundProperty], }; return border; }
public void Tapped_Should_Be_Raised_Even_When_PointerPressed_Handled() { Border border; var decorator = new Decorator { Child = border = new Border() }; var result = new List<string>(); border.AddHandler(Border.PointerPressedEvent, (s, e) => e.Handled = true); decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt")); border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt")); border.RaiseEvent(new PointerPressedEventArgs()); border.RaiseEvent(new PointerReleasedEventArgs()); Assert.Equal(new[] { "bt", "dt" }, result); }
public void Invalidating_Child_Should_Not_Invalidate_Parent() { var panel = new StackPanel(); var child = new Border(); panel.Children.Add(child); panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Assert.Equal(new Size(0, 0), panel.DesiredSize); child.Width = 100; child.Height = 100; Assert.True(panel.IsMeasureValid); Assert.False(child.IsMeasureValid); panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Assert.Equal(new Size(0, 0), panel.DesiredSize); }
public void GetTemplateChildren_Should_Not_Return_Nested_Template_Controls() { var target = new TestTemplatedControl(); var border1 = new Border { Name = "border1", TemplatedParent = target }; var inner = new TestTemplatedControl { Name = "inner", TemplatedParent = target }; var border2 = new Border { Name = "border2", TemplatedParent = inner }; var border3 = new Border { Name = "border3", TemplatedParent = inner }; var border4 = new Border { Name = "border4", TemplatedParent = target }; var border5 = new Border { Name = "border5", TemplatedParent = null }; target.AddVisualChild(border1); border1.Child = inner; inner.AddVisualChild(border2); inner.AddVisualChild(border3); border3.Child = border4; border4.Child = border5; var result = target.GetTemplateChildren().Select(x => x.Name).ToArray(); Assert.Equal(new[] { "border1", "inner", "border4" }, result); }
/// <summary> /// The default template for the <see cref="ProgressBar"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(ProgressBar control) { Border container = new Border { [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], Child = new Grid { MinHeight = 14, MinWidth = 200, Children = new Controls { new Border { Name = "PART_Track", BorderThickness = 1, [~Border.BorderBrushProperty] = control[~TemplatedControl.BackgroundProperty], }, new Border { Name = "PART_Indicator", BorderThickness = 1, HorizontalAlignment = HorizontalAlignment.Left, [~Border.BackgroundProperty] = control[~TemplatedControl.ForegroundProperty], Child = new Grid { Name = "Animation", ClipToBounds = true, } } } } }; return container; }
public void Grandchild_Size_Changed() { using (var context = PerspexLocator.EnterScope()) { RegisterServices(); Border border; TextBlock textBlock; var window = new Window() { SizeToContent = SizeToContent.WidthAndHeight, Content = border = new Border { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Child = new Border { Child = textBlock = new TextBlock { Width = 400, Height = 400, Text = "Hello World!", }, } } }; window.LayoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(400, 400), border.Bounds.Size); textBlock.Width = 200; window.LayoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(200, 400), border.Bounds.Size); } }
public void Adding_Tree_To_ILayoutRoot_Should_Style_Controls() { using (Locator.CurrentMutable.WithResolver()) { var root = new TestRoot(); var parent = new Border(); var child = new Border(); var grandchild = new Control(); var styler = new Mock<IStyler>(); Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); parent.Content = child; child.Content = grandchild; styler.Verify(x => x.ApplyStyles(It.IsAny<IStyleable>()), Times.Never()); root.Content = parent; styler.Verify(x => x.ApplyStyles(parent), Times.Once()); styler.Verify(x => x.ApplyStyles(child), Times.Once()); styler.Verify(x => x.ApplyStyles(grandchild), Times.Once()); } }
public void DoubleTapped_Should_Follow_Pointer_Pressed_Released_Pressed() { Border border; var decorator = new Decorator { Child = border = new Border() }; var result = new List<string>(); decorator.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("dp")); decorator.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("dr")); decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt")); decorator.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("ddt")); border.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("bp")); border.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("br")); border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt")); border.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("bdt")); border.RaiseEvent(new PointerPressedEventArgs()); border.RaiseEvent(new PointerReleasedEventArgs()); border.RaiseEvent(new PointerPressedEventArgs { ClickCount = 2 }); Assert.Equal(new[] { "bp", "dp", "br", "dr", "bt", "dt", "bp", "dp", "bdt", "ddt" }, result); }
public void Grandchild_Size_Changed() { using (var context = Locator.CurrentMutable.WithResolver()) { this.RegisterServices(); Border border; TextBlock textBlock; var window = new Window() { Content = (border = new Border { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = new Border { Content = (textBlock = new TextBlock { Width = 400, Height = 400, Text = "Hello World!", }), } }) }; window.LayoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(400, 400), border.Bounds.Size); textBlock.Width = 200; window.LayoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(200, 400), border.Bounds.Size); } }
/// <summary> /// The default template for a <see cref="DropDown"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(DropDown control) { Border result = new Border { [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], Child = new Grid { Name = "container", ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(new GridLength(1, GridUnitType.Star)), new ColumnDefinition(GridLength.Auto), }, Children = new Controls { new ContentControl { Name = "contentControl", Margin = new Thickness(3), [~ContentControl.ContentProperty] = control[~DropDown.SelectionBoxItemProperty], [~Layoutable.HorizontalAlignmentProperty] = control[~DropDown.HorizontalContentAlignmentProperty], [~Layoutable.VerticalAlignmentProperty] = control[~DropDown.VerticalContentAlignmentProperty], }, new ToggleButton { Name = "toggle", BorderThickness = 0, Background = Brushes.Transparent, ClickMode = ClickMode.Press, Focusable = false, Content = new Path { Name = "checkMark", Fill = Brushes.Black, Width = 8, Height = 4, Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = StreamGeometry.Parse("F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z"), [Grid.ColumnProperty] = 0, }, [~~ToggleButton.IsCheckedProperty] = control[~~DropDown.IsDropDownOpenProperty], [Grid.ColumnProperty] = 1, }, new Popup { Name = "popup", Child = new Border { BorderBrush = Brushes.Black, BorderThickness = 1, Padding = new Thickness(4), Child = new ItemsPresenter { [~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty], } }, PlacementTarget = control, StaysOpen = false, [~~Popup.IsOpenProperty] = control[~~DropDown.IsDropDownOpenProperty], [~Layoutable.MinWidthProperty] = control[~Visual.BoundsProperty].Cast<Rect>().Select(x => (object)x.Width), } }, }, }; return result; }
private Control Template(ToggleButton control) { Border border = new Border { Name = "border", Padding = new Thickness(3), [~Border.BackgroundProperty] = control[~ToggleButton.BackgroundProperty], [~Border.BorderBrushProperty] = control[~ToggleButton.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~ToggleButton.BorderThicknessProperty], Content = new ContentPresenter { Name = "contentPresenter", [~ContentPresenter.ContentProperty] = control[~ToggleButton.ContentProperty], [~ContentPresenter.HorizontalAlignmentProperty] = control[~ToggleButton.HorizontalContentAlignmentProperty], [~ContentPresenter.VerticalAlignmentProperty] = control[~ToggleButton.VerticalContentAlignmentProperty], }, }; return border; }
public void Content_Should_Have_TemplatedParent_Set_To_Null() { var target = new ContentControl(); var child = new Border(); target.Template = this.GetTemplate(); target.Content = child; target.ApplyTemplate(); Assert.Null(child.TemplatedParent); }
public void ContentPresenter_Should_Have_TemplatedParent_Set() { var target = new ContentControl(); var child = new Border(); target.Template = this.GetTemplate(); target.Content = child; target.ApplyTemplate(); var contentPresenter = child.GetVisualParent<ContentPresenter>(); Assert.Equal(target, contentPresenter.TemplatedParent); }
/// <inheritdoc/> protected override void OnTemplateApplied() { this.indicator = this.GetTemplateChild<Border>("PART_Indicator"); }
/// <summary> /// The default template for the <see cref="Button"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(Button control) { Border border = new Border { Name = "border", Padding = new Thickness(3), Child = new ContentPresenter { Name = "contentPresenter", [~ContentPresenter.ContentProperty] = control[~Button.ContentProperty], [~ContentPresenter.HorizontalAlignmentProperty] = control[~Button.HorizontalContentAlignmentProperty], [~ContentPresenter.VerticalAlignmentProperty] = control[~Button.VerticalContentAlignmentProperty], }, [~Border.BackgroundProperty] = control[~Button.BackgroundProperty], }; return border; }
/// <inheritdoc/> protected override void OnTemplateApplied() { _indicator = this.GetTemplateChild<Border>("PART_Indicator"); UpdateIndicator(Bounds.Size); }
private Control TopLevelTemplate(MenuItem control) { Popup popup; var result = new Border { Name = "root", [~Border.BackgroundProperty] = control[~MenuItem.BackgroundProperty], [~Border.BorderBrushProperty] = control[~MenuItem.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~MenuItem.BorderThicknessProperty], Child = new Panel { Children = new Controls { new ContentPresenter { DataTemplates = new DataTemplates { AccessKeyDataTemplate, }, [~ContentPresenter.ContentProperty] = control[~MenuItem.HeaderProperty], [~ContentPresenter.MarginProperty] = control[~MenuItem.PaddingProperty], [Grid.ColumnProperty] = 1, }, (popup = new Popup { Name = "popup", StaysOpen = true, [!!Popup.IsOpenProperty] = control[!!MenuItem.IsSubMenuOpenProperty], Child = new Border { Background = new SolidColorBrush(0xfff0f0f0), BorderBrush = new SolidColorBrush(0xff999999), BorderThickness = 1, Padding = new Thickness(2), Child = new ScrollViewer { Content = new Panel { Children = new Controls { new Rectangle { Name = "iconSeparator", Fill = new SolidColorBrush(0xffd7d7d7), HorizontalAlignment = HorizontalAlignment.Left, IsHitTestVisible = false, Margin = new Thickness(29, 2, 0, 2), Width = 1, }, new ItemsPresenter { Name = "itemsPresenter", [~ItemsPresenter.ItemsProperty] = control[~Menu.ItemsProperty], [~ItemsPresenter.ItemsPanelProperty] = control[~Menu.ItemsPanelProperty], [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle, } } } } } }) }, } }; popup.PlacementTarget = result; return result; }
/// <summary> /// The default template for the <see cref="TextBox"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(TextBox control) { Border result = new Border { Name = "border", Padding = new Thickness(2), [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], Child = new StackPanel { Children = new Controls.Controls { new TextBlock { Name = "floatingWatermark", Foreground = SolidColorBrush.Parse("#007ACC"), FontSize = 10, [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty], [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast<string>().Select(x => (object)(!string.IsNullOrEmpty(x) && control.UseFloatingWatermark)) }, new Panel { Children = new Controls.Controls { new TextBlock { Name = "watermark", Opacity = 0.5, [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty], [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast<string>().Select(x => (object)string.IsNullOrEmpty(x)) }, new ScrollViewer { [~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty], [~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty], [~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty], Content = new TextPresenter { Name = "textPresenter", [~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty], [~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty], [~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty], [~TextBlock.TextProperty] = control[~TextBox.TextProperty], [~TextBlock.TextWrappingProperty] = control[~TextBox.TextWrappingProperty], } } } } } }, }; return result; }
private Control PopupTemplate(MenuItem control) { Popup popup; var result = new Border { Name = "root", [~Border.BackgroundProperty] = control[~MenuItem.BackgroundProperty], [~Border.BorderBrushProperty] = control[~MenuItem.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~MenuItem.BorderThicknessProperty], Child = new Grid { ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(22, GridUnitType.Pixel), new ColumnDefinition(13, GridUnitType.Pixel), new ColumnDefinition(1, GridUnitType.Star), new ColumnDefinition(20, GridUnitType.Pixel), }, Children = new Controls { new ContentPresenter { Name = "icon", [~ContentPresenter.ContentProperty] = control[~MenuItem.IconProperty], Width = 16, Height = 16, Margin = new Thickness(3), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }, new Path { Data = StreamGeometry.Parse("F1M10,1.2L4.7,9.1 4.5,9.1 0,5.2 1.3,3.5 4.3,6.1 8.3,0 10,1.2z"), Margin = new Thickness(3), IsVisible = false, VerticalAlignment = VerticalAlignment.Center, [~Path.FillProperty] = control[~MenuItem.ForegroundProperty], }, new ContentPresenter { DataTemplates = new DataTemplates { AccessKeyDataTemplate, }, VerticalAlignment = VerticalAlignment.Center, [~ContentPresenter.ContentProperty] = control[~MenuItem.HeaderProperty], [~ContentPresenter.MarginProperty] = control[~MenuItem.PaddingProperty], [Grid.ColumnProperty] = 2, }, new Path { Name = "rightArrow", Data = StreamGeometry.Parse("M0,0L4,3.5 0,7z"), Fill = new SolidColorBrush(0xff212121), Margin = new Thickness(10, 0, 0, 0), UseLayoutRounding = false, VerticalAlignment = VerticalAlignment.Center, [Grid.ColumnProperty] = 3, }, (popup = new Popup { Name = "popup", PlacementMode = PlacementMode.Right, StaysOpen = true, [!!Popup.IsOpenProperty] = control[!!MenuItem.IsSubMenuOpenProperty], Child = new Border { Background = new SolidColorBrush(0xfff0f0f0), BorderBrush = new SolidColorBrush(0xff999999), BorderThickness = 1, Padding = new Thickness(2), Child = new ScrollViewer { Content = new Panel { Children = new Controls { new Rectangle { Name = "iconSeparator", Fill = new SolidColorBrush(0xffd7d7d7), HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(29, 2, 0, 2), Width = 1, }, new ItemsPresenter { Name = "itemsPresenter", [~ItemsPresenter.ItemsProperty] = control[~Menu.ItemsProperty], [~ItemsPresenter.ItemsPanelProperty] = control[~Menu.ItemsPanelProperty], [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle, } } } } } }) }, } }; popup.PlacementTarget = result; return result; }
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; }
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; }
public void Style_Should_Detach_When_Removed_From_Logical_Tree() { Border border; var style = new Style(x => x.OfType<Border>()) { Setters = new[] { new Setter(Border.BorderThicknessProperty, 4), } }; var root = new TestRoot { Child = border = new Border(), }; style.Attach(border, null); Assert.Equal(4, border.BorderThickness); root.Child = null; Assert.Equal(0, border.BorderThickness); }
/// <summary> /// The default template for a <see cref="CheckBox"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(CheckBox control) { Border result = new Border { [~Border.BackgroundProperty] = control[~CheckBox.BackgroundProperty], Child = new Grid { ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(GridLength.Auto), new ColumnDefinition(new GridLength(1, GridUnitType.Star)), }, Children = new Controls { new Border { Name = "checkBorder", BorderBrush = Brushes.Black, BorderThickness = 2, Width = 18, Height = 18, VerticalAlignment = VerticalAlignment.Center, [Grid.ColumnProperty] = 0, }, new Path { Name = "checkMark", Fill = Brushes.Black, Width = 11, Height = 10, Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = StreamGeometry.Parse("M 1145.607177734375,430 C1145.607177734375,430 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1141.449951171875,435.0772705078125 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1139.232177734375,433.0999755859375 1138,434.5538330078125 1138,434.5538330078125 1138,434.5538330078125 1141.482177734375,438 1141.482177734375,438 1141.482177734375,438 1141.96875,437.9375 1141.96875,437.9375 1141.96875,437.9375 1147,431.34619140625 1147,431.34619140625 1147,431.34619140625 1145.607177734375,430 1145.607177734375,430 z"), [Grid.ColumnProperty] = 0, }, new ContentPresenter { Name = "contentPresenter", Margin = new Thickness(4, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, [~ContentPresenter.ContentProperty] = control[~CheckBox.ContentProperty], [Grid.ColumnProperty] = 1, }, }, }, }; return result; }
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; }
/// <summary> /// The default template for the <see cref="Button"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(Button control) { Border border = new Border { Name = "border", Padding = new Thickness(3), Child = new ContentPresenter { Name = "contentPresenter", [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty], [~TextBlock.ForegroundProperty] = control[~TemplatedControl.ForegroundProperty], [~Layoutable.HorizontalAlignmentProperty] = control[~ContentControl.HorizontalContentAlignmentProperty], [~Layoutable.VerticalAlignmentProperty] = control[~ContentControl.VerticalContentAlignmentProperty], }, [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], }; return border; }
private Control Template(RadioButton control) { Border result = new Border { [~Border.BackgroundProperty] = control[~RadioButton.BackgroundProperty], Child = new Grid { ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(GridLength.Auto), new ColumnDefinition(new GridLength(1, GridUnitType.Star)), }, Children = new Controls { new Ellipse { Name = "checkBorder", Stroke = Brushes.Black, StrokeThickness = 2, Width = 18, Height = 18, VerticalAlignment = VerticalAlignment.Center, [Grid.ColumnProperty] = 0, }, new Ellipse { Name = "checkMark", Fill = Brushes.Black, Width = 10, Height = 10, Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, [Grid.ColumnProperty] = 0, }, new ContentPresenter { Name = "contentPresenter", Margin = new Thickness(4, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, [~ContentPresenter.ContentProperty] = control[~RadioButton.ContentProperty], [Grid.ColumnProperty] = 1, }, }, }, }; return result; }
/// <inheritdoc/> protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { _indicator = e.NameScope.Get<Border>("PART_Indicator"); UpdateIndicator(Bounds.Size); }