0
我在視圖按鈕:如何從視圖模型訪問CommandParameter值
<Button Grid.Row="0" Grid.Column="1" Content="Export to CSV "
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="2,2,20,2" Style="{StaticResource ExportButton}"
Command="{Binding ExportToExcelCommand}"
CommandParameter="{TelerikGrid}"
/>
現在,我有我的ViewModel
作爲ExportCommand
:
private RelayCommand _exportToExcelCommand;
public ICommand ExportToExcelCommand
{
get
{
if (_exportToExcelCommand == default(RelayCommand))
{
_exportToExcelCommand = new RelayCommand(ExportToExcel, CanExport);
}
return _exportToExcelCommand;
}
}
private void ExportToExcel(Object param)
{
try
{
//ToDo: Update With Command Parameters
RadGridView gdv = new RadGridView();
using (Stream stream = dialog.OpenFile())
{
gdv.Export(Columns);
}
}
catch (FaultException ex)
{
var faultMessage = ex.Reason.GetMatchingTranslation().Text + "/n" + ex.StackTrace;
}
}
現在我創建一個新的實例RadGridView:
RadGridView gdv = new RadGridView();
但是相反,我想分配gdv
從作爲CommandParameter
從XAML