1

I'm wondering if any one can explain why I can't use 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;
}

Wiring up other events in the above code works as expected, as does wiring up IsKeyboardFocusWithinChanged in the code behind.

Karlo
  • 1,630
  • 4
  • 33
  • 57
user1604008
  • 995
  • 9
  • 17

0 Answers0