簡體   English   中英

將超出的IntegerUpDown值綁定到CommandParameter

[英]Binding Exceed IntegerUpDown value to a CommandParameter

我在.xaml文件中使用Exceed IntegerUpDown控件。 我想將IntegerUpDown值綁定為按鈕的CommandParameter。

我在文件后面沒有任何代碼,這是一個自定義控件xaml文件。 所以我想僅通過使用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>

上面是我的xaml代碼。 這將使命令方法返回0。

我的命令類如下

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..
    }
}

找不到滿足要求的方法。 只需在此處發布以幫助以后解決此問題。

我使用了ViewModel變量來綁定IntegerUpDown控制值。

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

我的ViewModel如下,

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 
    }
}

希望這對以后的人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM