0
我用下面的代碼來獲得數據網格的文本菜單單擊視圖模型文本菜單點擊
代碼片段[XAML]
代碼片段[C#]
private BaseCommand exportcommand;
public BaseCommand ExportCommand
{
get
{
if (exportcommand == null)
exportcommand = new BaseCommand(ExportCommandExcecuted);
return exportcommand;
}
}
public void ExportCommandExcecuted(object param)
{
var grid = param as GridDataControl;
}
但我無法獲得作爲DataGrid的Command參數。你可以請看看這個,並提供建議,以實現ViewModel中的這個dataGrid。在此先感謝
你必須在XAML中設置'ContextMenu'的'PlacemenTarget'與數據網格本身...像'' –
@ WPF it it你不用「不得不」。 OP的'ContextMenu'在xaml的''內,如果我只是在切換CommandParameter的情況下完全複製它,那麼可以很好地獲得對'DataGrid'的引用。 –
Viv
是的,這是正確的。我的錯。 :-) –