エンジニアの備忘録

エンジニアの私が備忘録や思ったことをちょいちょい書いてます。

C# WPF-Tips-親階層のCommand実行

Command実行時にDataGridやListBox、ListView等
Commandの階層と異なるのでそのままCommandを書いても実行されません。

いつもの書き方

Command="{Binding ExeCommand}"

階層が異なる場合

Command="{Binding Path=DataContext.ExeCommand,
                     RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"