【发布时间】:2018-05-09 01:11:27
【问题描述】:
我有一个在 Prism 6 框架之上使用 c# 和 WPF 编写的应用程序。
我正在尝试使用 XAMl 创建一个按钮,单击时,我想将一个固定的十进制值传递给我的视图模型。
<Button Content="5"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Command="{Binding ProcessAmount}"
CommandParameter="5.00000"
FontSize="24"
Height="75"
Width="85" />
在我的视图模型中,我有以下内容
public class ViewModel : BindableBase
{
public DelegateCommand<decimal?> ProcessAmount { get; set; }
public ViewModel()
{
ProcessAmount = new DelegateCommand<decimal?>(HandleProcessAmount, CanProcessAmount);
}
private bool CanProcessAmount(decimal? amount)
{
return amount.HasValue && amount.Value != 0;
}
private void HandleProcessAmount(decimal? amount)
{
// do something with the amount
}
}
但是当我编译应用程序时,我在 XAML 视图中收到错误 Specified cast is not valid.
如何从视图中发送固定的十进制值?
【问题讨论】: