Decimals in value for CommandParameter

2 posts, 0 answers
  1. david mcintyre
    david mcintyre avatar
    31 posts
    Member since:
    Mar 2010

    Posted 24 Jan 2011 Link to this post

    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. 
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 25 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
Back to Top