AvaloniaUI / Avalonia.Xaml.Behaviors

Port of Windows UWP Xaml Behaviors for Avalonia Xaml.
MIT License
385 stars 46 forks source link

InvokeCommandAction on listbox items #116

Closed GuilhermeRaposo closed 6 months ago

GuilhermeRaposo commented 1 year ago

How do I invoke a command when a listbox item is double clicked?

<ListBox Items="{ Binding Accounts }" SelectedItem="{ Binding SelectedAccount }" ScrollViewer.VerticalScrollBarVisibility="Visible" Grid.Row="2">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock x:Name="{ Binding AccountName }" Text="{ Binding AccountName }">
                <i:Interaction.Behaviors>
                    <ia:EventTriggerBehavior EventName="DoubleTapped" SourceObject="{ Binding AccountName }">
                        <ia:InvokeCommandAction Command="{ Binding Login }" />
                    </ia:EventTriggerBehavior>
                </i:Interaction.Behaviors>
            </TextBlock>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

This doesn't seem to work, but if I wrap the behavior inside a Button and change the SourceObject to the button it works normally.