我想知道是否有人可以解释为什么我不能使用IsKeyboardFocusWithinChanged
with EventTrigger
:
<StackPanel>
<TextBox >
<i:Interaction.Triggers>
<i:EventTrigger EventName="IsKeyboardFocusWithinChanged">
<i:InvokeCommandAction Command="{Binding Path=SomeCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<Button Content="Click Me" />
</StackPanel>
public partial class MainWindow : Window
{
public ICommand SomeCommand { get; set; }
public MainWindow()
{
InitializeComponent();
SomeCommand = new SampleCommand();
DataContext = this;
}
}
public class SampleCommand : ICommand
{
public void Execute(object parameter) { MessageBox.Show("Bingo"); }
public bool CanExecute(object parameter) { return true; }
public event EventHandler CanExecuteChanged;
}
在上述代码中连接其他事件按预期工作,IsKeyboardFocusWithinChanged
在后面的代码中连接也是如此。