0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WPF + MVVM で ListViewItem の MouseDoubleClick から ViewModel の ICommand を呼ぶ方法

Last updated at Posted at 2021-06-01

NuGet で AttachedCommandBehavior を追加

ViewModel
Public ReactiveCommand<T> Hoge { get; set; }
View
xmlns:cb="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"

<ListView>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="cb:CommandBehavior.Event" Value="MouseDoubleClick" />
            <Setter Property="cb:CommandBehavior.Command" Value="{Binding Path=DataContext.Hoge, RelativeSource={RelativeSource AncestorType=Window}}" />
            <Setter Property="cb:CommandBehavior.CommandParameter" Value="{Binding}" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListView>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?