gpt4 book ai didi

c# - 如何从 View 模型访问CommandParameter值

转载 作者:行者123 更新时间:2023-12-03 11:00:04 28 4
gpt4 key购买 nike

我在 View 中有一个按钮:

<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}"
/>

现在我的 ExportCommand中的 ViewModel为:
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();

但是我想从XAML作为 gdv传递的值分配 CommandParameter

最佳答案

RadGridView gdv = (RadGridView)param;
param是您发送的对象,因此只需将其转换为它的来源即可。

关于c# - 如何从 View 模型访问CommandParameter值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15088086/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com