How to make a movable control in Avalonia?

How do controls work?

How to make custom controls?

public class CustomMovableBorder : Border
{
/* We will do our modification here */
}

How to work with mouse pointer?

  • PointerPressed get’s fired when we press the left click of our mouse over the control.
  • PointerReleased get’s fired when we release(leave) the left click of our mouse over the control.
  • PointerMoved get’s fired when we move the mouse pointer over the control.
public class CustomMovableBorder : Border
{
protected override void OnPointerPressed(PointerPressedEventArgs e)
{

base.OnPointerPressed(e);
}
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{

base.OnPointerReleased(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{

base.OnPointerMoved(e);
}
}
  1. A property to detect if the mouse left click is pressed or not. It will be a type of bool.
  2. A property to save the previous position of the mouse pointer in memory. It will be a type of Point.
  3. A property to save the previous position of the control in the parent control in memory. It will be a type of TranslateTransform.
A working example of CustomMovableControl

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abdella Solomon

Abdella Solomon

A 17yo Data Scientist | Programmer | Writer | Freelancer | Lecturer