将命令绑定到TextBox
LostFocus
事件。
XAML
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
<TextBox Margin="0,287,0,0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding LostFocusCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
查看模型
private ICommand lostFocusCommand;
public ICommand LostFocusCommand
{
get
{
if (lostFocusCommand== null)
{
lostFocusCommand= new RelayCommand(param => this.LostTextBoxFocus(), null);
}
return lostFocusCommand;
}
}
private void LostTextBoxFocus()
{
// do your implementation
}
你必须参考System.Windows.Interactivity
这个。你必须安装一个可再发行组件才能使用这个库。你可以从这里下载