C#C
C#3y ago
Angius

✅ Avalonia — stop children from triggering parent events

<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" 
            Orientation="Horizontal" 
            Background="Black" 
            Opacity="0.7" PointerPressed="InputElement_OnPointerPressed">
    <Button Command="{Binding NewWindowCommand}">S</Button>
    <Button Command="{Binding MainViewCommand}">Home</Button>
</StackPanel>

with the following codebehind
private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
    BeginMoveDrag(e);
}

makes it so that clicking on the buttons doesn't trigger their commands, but rather the click gets captured by the parent and the window gets dragged
Was this page helpful?