我有這種問題。 我通常通過左鍵或右鍵點擊選擇datagrid中的行。 但我需要在右鍵單擊運行命令。 我使用此代碼C#MVVM選擇行並運行命令
<DataGrid.InputBindings> <MouseBinding Command="{Binding ShowDWClickOnRightButton}" MouseAction="RightClick" CommandParameter="{Binding ElementName=myDataGrid, Path=SelectedItem}"/> </DataGrid.InputBindings>
但這不工作,因爲在命令參數我有空(無選擇項)。你能給我一些建議如何解決這個問題嗎?
謝謝
我寫了一個行爲,選擇項上單擊鼠標右鍵。這是一個TreeView,但我認爲你可以調整它爲一個GridView。看看:https://stackoverflow.com/a/43118460/7713750 – Rekshino
我試着檢查你的解決方案...我需要選擇和運行命令選定的行。所以希望這是可能的。 – MarekJ