wpf - 将命令绑定(bind)到 xctk :IntegerUpDown 的 'LostMouseCapture' 事件

标签 wpf events mvvm data-binding command

我想将 Icommand 绑定(bind)到 xctk:IntegerUpDown 的事件。事件是“LostMouseCapture”

在 XAML 中:

<xctk:IntegerUpDown Name="MinColor" ClipValueToMinMax="True" Grid.Column="2" 
                                                    Minimum="0" Maximum="{Binding Path=MinColorMaxValue}" Value="{Binding Path=MinColorValue}" Increment="1"   
                                                    PreviewTextInput="IntegerUpDown_PreviewTextInput" DataObject.Pasting="IntegerUpDown_Pasting" PreviewKeyDown="IntegerUpDown_PreviewKeyDown" >
                                                    <i:Interaction.Triggers>
                                                        <i:EventTrigger EventName="LostMouseCapture">
                                                            <i:InvokeCommandAction Command="{Binding Path=ValueCommand}" CommandParameter="{Binding FileName}"/>
                                                        </i:EventTrigger>
                                                    </i:Interaction.Triggers>
                                                </xctk:IntegerUpDown> 

在 View 模型中:
private DelegateCommand m_ValueCommand = null;          

    public ICommand ValueCommand
    {
        get
        {
            if (m_ValueCommand == null)
                m_ValueCommand = new DelegateCommand(new Action<object>(ExecuteValueCommand),
                    new Predicate<object>(CanExecuteValueCommand));
            return m_ValueCommand;
        }
    }

    public bool CanExecuteValueCommand(object sender)
    {  
        return true;
    }

    public void ExecuteValueCommand(object sender)
    {
    }

当我在 IntegerUpdown 中输入一些值并单击外部时,我想调用“ValueCommand”。有什么解决办法吗?

最佳答案

从您的 MinColorValue 的 setter 中调用您的命令源属性:

private int _minColorValue;
public int MinColorValue
{
    get { return _minColorValue; }
    set
    {
        _minColorValue = value;
        ValueCommand.Execute(FileName);
    }
}

或尝试处理LostKeyboardFocusLostFocus事件:
<i:EventTrigger EventName="LostKeyboardFocus">

关于wpf - 将命令绑定(bind)到 xctk :IntegerUpDown 的 'LostMouseCapture' 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45632832/

相关文章:

wpf - 如何在运行时更改 WPF 窗口内容

c# - 无法从 DragEventArgs 获取数据。 getData() 返回空值

javascript - 当我的函数完成时,使用 JavaScript(或 jQuery)触发自定义事件

c# - 通过 View 模型图/树进行验证

wpf - 如何从属性 setter 调用异步方法

c# - 通过 WPF 发送电子邮件使应用程序关闭

email - 事件跟踪,尤其是在电子邮件上的事件谷歌分析不起作用

javascript - jQuery DataTables - 行点击不在第一页以外的页面上注册

c# - MVVM模式: Commands for several GUI events?

c# - WPF - UI 未从命令更新