【问题标题】:Binding Exceed IntegerUpDown value to a CommandParameter将 Exceed IntegerUpDown 值绑定到 CommandParameter
【发布时间】:2018-11-22 20:21:08
【问题描述】:

我在我的 .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。我想看看你是如何创建Command
  • @TomerAgmon1 我已经更新了这个问题。请检查

标签: c# xaml exceed integerupdown


【解决方案1】:

找不到满足要求的方法。只是在这里发帖以帮助稍后解决此问题的人。

我使用 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 
    }
}

希望这对以后的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 2017-05-16
    • 2013-09-22
    • 1970-01-01
    • 2015-09-10
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多