10/01/23 22:52:04
あれ?もしかしたら違うところで躓いてるかも…。
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button c:Click.Command="{Binding MyCommand}" ←このMyCommandはItemsにはなく、DataContextのViewModelにある。
c:Click.CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
この状態でButtonをクリックするとMyCommand自体が呼ばれません。
ItemsControlの外に置くとうまくBindされてMyCommandは実行されます。
これはおそらくItemsの中にMyCommandがないからだと思われますがうまく"Binding MyCommand"の箇所をViewModelのMyCommandが呼ばれるようにするにはどう設定すればよいのでしょうか?
Binding ../MyCommand←これはだめでした。
Binding this.DataContext.MyCommand←これもだめ。
うーん…。