我想将 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);
}
}
或尝试处理
LostKeyboardFocus
或 LostFocus
事件:<i:EventTrigger EventName="LostKeyboardFocus">
关于wpf - 将命令绑定(bind)到 xctk :IntegerUpDown 的 'LostMouseCapture' 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45632832/