This is a migrated thread and some comments may be shown as answers.

Decimals in value for CommandParameter

1 Answer 231 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
david mcintyre
Top achievements
Rank 1
david mcintyre asked on 24 Jan 2011, 11:17 PM
I have a ribbon bar containing a RadRibbonButton that is bound to a command in my VM.  The numericupdown control supplies the command parameter, which my command expects to be an integer.  But there doesn't seem to be any way to get the numeric updown control to provide the user's selected value as an integer.  Here's a snippet of my xaml:
<telerikRibbonBar:RadRibbonSplitButton >                            <telerikRibbonBar:RadRibbonSplitButton.DropDownContent>
                                <StackPanel>
                                    <telerikInput:RadNumericUpDown x:Name="updownDays" IsInteger="True"  SmallChange="1" Minimum="0" ValueFormat="Numeric" HorizontalAlignment="Stretch" /> 
                                    <telerikRibbonBar:RadRibbonButton Command="{Binding MyCommand}" CommandParameter="{Binding ElementName=updownDays, Path=Value}">
                                        <StackPanel Orientation="Horizontal">
                                            <Image  Source="/MyImage.png" HorizontalAlignment="Stretch"/>
                                            <TextBlock Text="Add">
                                        </StackPanel>
                                    </telerikRibbonBar:RadRibbonButton> </StackPanel>
                            </telerikRibbonBar:RadRibbonSplitButton.DropDownContent>
                        </telerikRibbonBar:RadRibbonSplitButton>
If I add an event handler for the button's click event, the button's CommandParameter value always has a single digit after the decimal point (i.e., 5.0 instead of the desired '5').  As a result, the following command is never activated:
public GalaSoft.MvvmLight.Command.RelayCommand<int> MyCommand{ get; private set; } 
MyCommand = new GalaSoft.MvvmLight.Command.RelayCommand<int>((days) => Execute(days));
 Is there any way to get rid of the trailing zero?  I can get my command to be activated if i change the expected parameter type from int to double, but it seems odd to have to do that. 

1 Answer, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 25 Jan 2011, 09:40 AM
Hello ,

You can put a converter in the CommandParameter Binding where to convert the double from the Value property to int.

Kind regards,
Valeri Hristov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
NumericUpDown
Asked by
david mcintyre
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Share this question
or