【发布时间】:2012-10-29 03:17:39
【问题描述】:
我正在使用 Silverlight 应用程序。尝试将按钮的单击命令绑定到 ViewModel 中的中继命令并将一些参数传递给它。我的视图代码是:
<Button x:Name="button" Content="Button" VerticalAlignment="Top" Margin="173,0,152,0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction CommandParameter="{Binding ActualWidth, ElementName=button, Mode=TwoWay}" Command="{Binding CRelayDecimal, Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
按钮将其 ActualWidth 作为参数传递给命令的参数。我的 ViewModel 代码是:
public Page1()
{
InitializeComponent();
CRelayDecimal = new RelayCommand<Object>(this.GetDecimal);
}
public RelayCommand<Object> CRelayDecimal { get; private set; }
private void GetDecimal(Object Obj)
{
var value = (double)Obj;
}
现在,我在这里看到的问题是,大多数时候我收到的传递参数值是 0.0。时不时地,我看到 value 是应该的精确值(例如 75.0)。
还有其他方法吗?
提前感谢大家的帮助。
感谢和问候
尼桑特拉纳
【问题讨论】:
标签: wpf silverlight mvvm-light