Is it possible to enable preview using InputBindings in WPF?

I want to determine when the user clicks on an item in the list, without using events, as I am binding the command and I don’t like all the stupid behavior. I tried this:

<ListView x:Name="MainList" Margin="2,8,6,8" Background="Black" 
   ItemsSource="{Binding Path=AssetsVM.Data, Mode=OneWay}" 
   BorderBrush="{x:Null}" >

    <ListView.InputBindings>
         <MouseBinding Command="{Binding Path=AssetsVM.SelectActivo}" 
            CommandParameter="{Binding ElementName=MainList, Path=SelectedItem}" 
            MouseAction="LeftClick" />
    </ListView.InputBindings>

This works fine if I click on a list but does not work on items. I need either a way to enable Preview, or MouseAction / Gesture, which behaves like a preview. Is one of them possible?

0
source share
1 answer

, , AttachedCommandBehavior, , Microsoft MouseBinding.Command a DependencyProperty. , , :

<ListView x:Name="MainList" ItemsSource="{Binding Path=AssetsVM.Data, Mode=OneWay}">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Style.Setters>
                <Setter Property="acb:CommandBehavior.Event" Value="Selected" />
                <Setter Property="acb:CommandBehavior.Command" Value="{Binding DataContext.AssetsVM.SelectActivo, ElementName=MainList}" />
                <Setter Property="acb:CommandBehavior.CommandParameter" Value="{Binding}" />
            </Style.Setters>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>
0

Source: https://habr.com/ru/post/1739715/


All Articles