Binding Exceed IntegerUpDown value to a CommandParameter

631 Views Asked by At

I am using Exceed IntegerUpDown control in my .xaml file. I want to bind IntegerUpDown value as a CommandParameter of a button.

I do not have any code behind files and this is a custom control xaml file. So i want to achieve this by only using xaml systax.

<DockPanel>
    <xctk:IntegerUpDown x:Name="ExtraExpressionValue" Increment="1" FormatString="N0" AllowSpin="True" Width="70" Watermark="Numeric" AllowTextInput="False" Minimum="0" Value="999"/>
    <Button Style="{StaticResource ContextMenuButton}" Margin="5,0,0,0" Content="Add" Command="{Binding SetExtaExpressionValueCommand}" CommandParameter="{Binding ElementName=ExtraExpressionValue,Path=Value}"/>
</DockPanel>

Above is my xaml code. this return 0 to command method.

My command class is as follows,

public class DesignItemCommands
{
    private ICommand setExtaExpressionValueCommand;

    public ICommand SetExtaExpressionValueCommand => setExtaExpressionValueCommand ?? (setExtaExpressionValueCommand = new CommandHandler(SetExtaExpressionValue, canExecute));

    private bool canExecute;

    public DesignItemCommands()
    {
        canExecute = true;
    }

    private void SetExtaExpressionValue(object parameter)
    {
        //I need parameter here..
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

Couldn't find a way on the requirement. Just posting here to help someone later on this issue.

I used a ViewModel Variable to bind IntegerUpDown control value.

<DockPanel>
    <xctk:IntegerUpDown Increment="1" Value="{Binding ExtraExpressionValue}"/>
    <Button Content="Add" Command="{Binding SetExtaExpressionValueCommand}"/>
</DockPanel>

My ViewModel is as follows,

public class DesignItemCommands
{
    private ICommand setExtaExpressionValueCommand;

    public ICommand SetExtaExpressionValueCommand => setExtaExpressionValueCommand ?? (setExtaExpressionValueCommand = new CommandHandler(SetExtaExpressionValue, canExecute));

    private bool canExecute;

    public int ExtraExpressionValue { get; set; }

    public DesignItemCommands()
    {
        canExecute = true;
        ExtraExpressionValue = 1;
    }

    private void SetExtaExpressionValue(object parameter)
    {
        //I can use value here using variable ExtraExpressionValue 
    }
}

Hope this helps someone later.