private void SetupAddRowToHostFunctionsIfAny(Avalonia.Controls.Control row, AddRowToHostFunctions functions = null) { if (functions != null) { functions.show = () => { row.IsVisible = true; }; functions.hide = () => { row.IsVisible = false; }; } }
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); }
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); } }
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); }
/// <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))); }
/// <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); }
/// <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); }
/// <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); }
/// <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)); }
public static void SetPreviewWith(object target, Control control) { Substitutes.Remove(target); Substitutes.Add(target, control); }
/// <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)); }
public static void SetDataContext(Control control, object value) { control.SetValue(DataContextProperty, value); }
public static object GetDataContext(Control control) { return control.GetValue(DataContextProperty); }
public static void SetWidth(Control control, double value) { control.SetValue(WidthProperty, value); }
public static double GetWidth(Control control) { return control.GetValue(WidthProperty); }
public static void SetHeight(Control control, double value) { control.SetValue(HeightProperty, value); }
public static double GetHeight(Control control) { return control.GetValue(HeightProperty); }
/// <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)); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Init. /// </summary> public ControlAdapter(Control control) : base(AvaloniaAdapter.Instance) { ArgChecker.AssertArgNotNull(control, "control"); _control = control; }
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; } }); }
protected void RemoveAdorner(object sender, PointerEventArgs e) { if (_adorner != null) { ((Panel)_adorner.Parent).Children.Remove(_adorner); _adorner = null; } }
/// <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); }
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 }); } } }
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); } }
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); }
/// <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; } }