The visual experience of the button is caused by the different states of the pointer.
Therefore, it is too complex to call these externally.
For the conditions described in your use case, it would be much easier to make the button draggable.
If you want both click and drag events to coexist, the code would look as below.
<local:ButtonEx
ClickMode="Release"
Click="myButton_Click"
Content="Drag or Click Me!">
</local:ButtonEx>
class ButtonEx : Button
{
protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
if (this.CapturePointer(e.Pointer))
{
pressPoint = e.GetCurrentPoint(this);
WireDragEvent(this);
}
base.OnPointerPressed(e);
}
private Microsoft.UI.Input.PointerPoint pressPoint;
private void WireDragEvent(Button btn)
{
btn.PointerMoved += btn_PointerMoved;
btn.PointerReleased += Btn_PointerReleased;
btn.PointerCaptureLost += btn_PointerCaptureLost;
}
private void ReleaseDragEvent(Button btn)
{
btn.PointerMoved -= btn_PointerMoved;
btn.PointerReleased -= Btn_PointerReleased;
btn.PointerCaptureLost -= btn_PointerCaptureLost;
}
private async void btn_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var btn = (Button)sender;
var currentPoint = e.GetCurrentPoint(btn);
var dx = currentPoint.Position.X - pressPoint.Position.X;
var dy = currentPoint.Position.Y - pressPoint.Position.Y;
var def = dx * dx + dy * dy;
if (dx > 4)
{
ReleaseDragEvent(btn);
btn.ReleasePointerCapture(e.Pointer);
await btn.StartDragAsync(pressPoint);
}
}
private void Btn_PointerReleased(object sender, PointerRoutedEventArgs e)
{
var btn = (Button)sender;
ReleaseDragEvent(btn);
btn.ReleasePointerCapture(e.Pointer);
}
private void btn_PointerCaptureLost(object sender, PointerRoutedEventArgs e)
{
var btn = (Button)sender;
ReleaseDragEvent(btn);
}
}
C# and XAML used for easy make of sample.