I am using a silverlight application. Trying to bind a button’s click command to a relay command in ViewModel and passing some parameters to it. Code for my View is :
<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>
A button is passing it’s ActualWidth as parameter for command’s parameter. My ViewModel code is:
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;
}
Now, the problem I see here is that most of the time passed parameter value I receive is 0.0. Intermittently, I’ve seen value to be precise value (like.. 75.0) that it should be.
Is there any other way of doing it ?
Thanks you all for your help in advance.
Thanks and Regards
Nishant Rana
Okay Got the answer why this was not working.. because it’s a known issue in silverlight.
Read this link for details from MSFT.