Beispiel #1
0
 private void SetupAddRowToHostFunctionsIfAny(Avalonia.Controls.Control row, AddRowToHostFunctions functions = null)
 {
     if (functions != null)
     {
         functions.show = () =>
         {
             row.IsVisible = true;
         };
         functions.hide = () =>
         {
             row.IsVisible = false;
         };
     }
 }
Beispiel #2
0
        public void DataContext_Binding_Should_Produce_Correct_Results()
        {
            var root = new Decorator
            {
                DataContext = new { Foo = "bar" },
            };

            var child = new Control();
            var dataContextBinding = new Binding("Foo");
            var values = new List<object>();

            child.GetObservable(Border.DataContextProperty).Subscribe(x => values.Add(x));
            child.Bind(ContentControl.DataContextProperty, dataContextBinding);

            root.Child = child;

            Assert.Equal(new[] { null, "bar" }, values);
        }
Beispiel #3
0
        protected void RenderToFile(Control target, [CallerMemberName] string testName = "")
        {
            if (!Directory.Exists(OutputPath))
            {
                Directory.CreateDirectory(OutputPath);
            }

            string path = Path.Combine(OutputPath, testName + ".out.png");

            using (RenderTargetBitmap bitmap = new RenderTargetBitmap(
                (int)target.Width,
                (int)target.Height))
            {
                Size size = new Size(target.Width, target.Height);
                target.Measure(size);
                target.Arrange(new Rect(size));
                bitmap.Render(target);
                bitmap.Save(path);
            }
        }
Beispiel #4
0
        public void DataContext_Binding_Should_Track_Parent()
        {
            var parent = new Decorator
            {
                DataContext = new { Foo = "foo" },
            };

            var child = new Control();

            var binding = new Binding
            {
                Path = "Foo",
            };

            child.Bind(Control.DataContextProperty, binding);

            Assert.Null(child.DataContext);
            parent.Child = child;
            Assert.Equal("foo", child.DataContext);
        }
Beispiel #5
0
        /// <summary>
        /// Handle mouse double click to select word under the mouse.
        /// </summary>
        /// <param name="parent">the control hosting the html to set cursor and invalidate</param>
        /// <param name="e">mouse event args</param>
        public void HandleMouseDoubleClick(Control parent, PointerEventArgs e)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");
            ArgChecker.AssertArgNotNull(e, "e");

            _htmlContainerInt.HandleMouseDoubleClick(new ControlAdapter(parent), Util.Convert(e.GetPosition(parent)));
        }
Beispiel #6
0
 /// <summary>
 /// Gets the value of the VerticalScrollBarVisibility attached property.
 /// </summary>
 /// <param name="control">The control to set the value on.</param>
 /// <param name="value">The value of the property.</param>
 public void SetVerticalScrollBarVisibility(Control control, ScrollBarVisibility value)
 {
     control.SetValue(VerticalScrollBarVisibilityProperty, value);
 }
Beispiel #7
0
 /// <summary>
 /// Gets the value of the HorizontalScrollBarVisibility attached property.
 /// </summary>
 /// <param name="control">The control to set the value on.</param>
 /// <param name="value">The value of the property.</param>
 public void SetHorizontalScrollBarVisibility(Control control, ScrollBarVisibility value)
 {
     control.SetValue(HorizontalScrollBarVisibilityProperty, value);
 }
Beispiel #8
0
 /// <summary>
 /// Gets the value of the VerticalScrollBarVisibility attached property.
 /// </summary>
 /// <param name="control">The control to read the value from.</param>
 /// <returns>The value of the property.</returns>
 public ScrollBarVisibility GetVerticalScrollBarVisibility(Control control)
 {
     return control.GetValue(VerticalScrollBarVisibilityProperty);
 }
Beispiel #9
0
        /// <summary>
        /// Handle mouse move to handle hover cursor and text selection.
        /// </summary>
        /// <param name="parent">the control hosting the html to set cursor and invalidate</param>
        /// <param name="mousePos">the mouse event args</param>
        public void HandleMouseMove(Control parent, Point mousePos)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");

            _htmlContainerInt.HandleMouseMove(new ControlAdapter(parent), Util.Convert(mousePos));
        }
Beispiel #10
0
 public static void SetPreviewWith(object target, Control control)
 {
     Substitutes.Remove(target);
     Substitutes.Add(target, control);
 }
Beispiel #11
0
        /// <summary>
        /// Handle key down event for selection and copy.
        /// </summary>
        /// <param name="parent">the control hosting the html to invalidate</param>
        /// <param name="e">the pressed key</param>
        public void HandleKeyDown(Control parent, KeyEventArgs e)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");
            ArgChecker.AssertArgNotNull(e, "e");

            _htmlContainerInt.HandleKeyDown(new ControlAdapter(parent), CreateKeyEevent(e));
        }
Beispiel #12
0
 public static void SetDataContext(Control control, object value)
 {
     control.SetValue(DataContextProperty, value);
 }
Beispiel #13
0
 public static object GetDataContext(Control control)
 {
     return control.GetValue(DataContextProperty);
 }
Beispiel #14
0
 public static void SetWidth(Control control, double value)
 {
     control.SetValue(WidthProperty, value);
 }
Beispiel #15
0
 public static double GetWidth(Control control)
 {
     return control.GetValue(WidthProperty);
 }
Beispiel #16
0
 public static void SetHeight(Control control, double value)
 {
     control.SetValue(HeightProperty, value);
 }
Beispiel #17
0
 public static double GetHeight(Control control)
 {
     return control.GetValue(HeightProperty);
 }
Beispiel #18
0
        /// <summary>
        /// Handle mouse leave to handle hover cursor.
        /// </summary>
        /// <param name="parent">the control hosting the html to set cursor and invalidate</param>
        public void HandleMouseLeave(Control parent)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");

            _htmlContainerInt.HandleMouseLeave(new ControlAdapter(parent));
        }
Beispiel #19
0
        /// <summary>
        /// Handle mouse up to handle selection and link click.
        /// </summary>
        /// <param name="parent">the control hosting the html to invalidate</param>
        /// <param name="e">the mouse event args</param>
        public void HandleLeftMouseUp(Control parent, PointerEventArgs e)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");
            ArgChecker.AssertArgNotNull(e, "e");

            var mouseEvent = new RMouseEvent(true);
            _htmlContainerInt.HandleMouseUp(new ControlAdapter(parent), Util.Convert(e.GetPosition(parent)), mouseEvent);
        }
Beispiel #20
0
 /// <summary>
 /// Sets the value of the Dock attached property on the specified control.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="value">The value of the Dock property.</param>
 public static void SetDock(Control control, Dock value)
 {
     control.SetValue(DockProperty, value);
 }
Beispiel #21
0
 /// <summary>
 /// Gets the value of the HorizontalScrollBarVisibility attached property.
 /// </summary>
 /// <param name="control">The control to read the value from.</param>
 /// <returns>The value of the property.</returns>
 public ScrollBarVisibility GetHorizontalScrollBarVisibility(Control control)
 {
     return control.GetValue(HorizontalScrollBarVisibilityProperty);
 }
Beispiel #22
-1
        /// <summary>
        /// Init.
        /// </summary>
        public ControlAdapter(Control control)
            : base(AvaloniaAdapter.Instance)
        {
            ArgChecker.AssertArgNotNull(control, "control");

            _control = control;
        }
Beispiel #23
-1
        public TreeNode(Control control, TreeNode parent)
        {
            Control = control;
            Parent = parent;
            Type = control.GetType().Name;

            var classesChanged = Observable.FromEventPattern<
                    NotifyCollectionChangedEventHandler, 
                    NotifyCollectionChangedEventArgs>(
                x => control.Classes.CollectionChanged += x,
                x => control.Classes.CollectionChanged -= x)
                .TakeUntil(((IStyleable)control).StyleDetach);

            classesChanged.Select(_ => Unit.Default)
                .StartWith(Unit.Default)
                .Subscribe(_ =>
                {
                    if (control.Classes.Count > 0)
                    {
                        Classes = "(" + string.Join(" ", control.Classes) + ")";
                    }
                    else
                    {
                        Classes = string.Empty;
                    }
                });
        }
Beispiel #24
-1
 protected void RemoveAdorner(object sender, PointerEventArgs e)
 {
     if (_adorner != null)
     {
         ((Panel)_adorner.Parent).Children.Remove(_adorner);
         _adorner = null;
     }
 }
Beispiel #25
-1
 /// <summary>
 /// Initializes a new instance of the <see cref="AvaloniaInputSource"/> class.
 /// </summary>
 /// <param name="source">The source element.</param>
 /// <param name="relative">The relative element.</param>
 /// <param name="translate">The translate function.</param>
 public AvaloniaInputSource(Control source, Control relative, Func<Point, Point> translate)
 {
     LeftDown = GetPressedObservable(source, "PointerPressed", relative, translate, MouseButton.Left);
     LeftUp = GetReleasedObservable(source, "PointerReleased", relative, translate, MouseButton.Left);
     RightDown = GetPressedObservable(source, "PointerPressed", relative, translate, MouseButton.Right);
     RightUp = GetReleasedObservable(source, "PointerReleased", relative, translate, MouseButton.Right);
     Move = GetMoveObservable(source, "PointerMoved", relative, translate);
 }
Beispiel #26
-1
 internal static void ApplyDesignerProperties(Control target, Control source)
 {
     if (source.IsSet(WidthProperty))
         target.Width = source.GetValue(WidthProperty);
     if (source.IsSet(HeightProperty))
         target.Height = source.GetValue(HeightProperty);
     if (source.IsSet(DataContextProperty))
         target.DataContext = source.GetValue(DataContextProperty);
 }
 public ControlDetailsViewModel(Control control)
 {
     if (control != null)
     {
         Properties = AvaloniaPropertyRegistry.Instance.GetRegistered(control)
             .Select(x => new PropertyDetails(control, x))
             .OrderBy(x => x.IsAttached)
             .ThenBy(x => x.Name);
     }
 }
		public void BindKeyGestures(Control uiElement)
		{
			foreach (var keyboardShortcut in _keyboardShortcuts)
			{
				if (keyboardShortcut.KeyGesture != null)
				{
					(uiElement as Window)?.KeyBindings.Add(new KeyBinding
					{
						Gesture = keyboardShortcut.KeyGesture,
						Command = keyboardShortcut.CommandDefinition.Command
					});
				}
			}
		}
Beispiel #29
-1
        protected void AddAdorner(object sender, PointerEventArgs e)
        {
            var node = (TreeNode)((Control)sender).DataContext;
            var layer = AdornerLayer.GetAdornerLayer(node.Control);

            if (layer != null)
            {
                _adorner = new Rectangle
                {
                    Fill = new SolidColorBrush(0x80a0c5e8),
                    [AdornerLayer.AdornedElementProperty] = node.Control,
                };

                layer.Children.Add(_adorner);
            }
        }
Beispiel #30
-1
        public void Negative_Margin_Larger_Than_Constraint_Should_Request_Height_0()
        {
            Control target;

            var outer = new Decorator
            {
                Width = 100,
                Height = 100,
                Child = target = new Control
                {
                    Margin = new Thickness(0, -100, 0, 0),
                }
            };

            outer.Measure(Size.Infinity);

            Assert.Equal(0, target.DesiredSize.Height);
        }
Beispiel #31
-1
        /// <summary>
        /// Shows a context menu for the specified control.
        /// </summary>
        /// <param name="control">The control.</param>
        private void Show(Control control)
        {
            if (control != null)
            {
                if(_popup == null)
                {
                    _popup = new Popup()
                    {
                        PlacementMode = PlacementMode.Pointer,
                        PlacementTarget = control,
                        StaysOpen = false                                         
                    };

                    _popup.Closed += PopupClosed;
                }

                ((ISetLogicalParent)_popup).SetParent(control);
                _popup.Child = control.ContextMenu;

                _popup.Open();

                control.ContextMenu._isOpen = true;
            }
        }