我想将Icommand绑定到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>
在ViewModel中:
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'。对此有什么解决方案吗?
答案 0 :(得分:1)
从MinColorValue
源属性的设置者中调用您的命令:
private int _minColorValue;
public int MinColorValue
{
get { return _minColorValue; }
set
{
_minColorValue = value;
ValueCommand.Execute(FileName);
}
}
或尝试处理LostKeyboardFocus
或LostFocus
事件:
<i:EventTrigger EventName="LostKeyboardFocus">