Search code examples
wpfwpf-controlswpfdatagrid

How to use LostFocus as a Command in WPF


I am trying to use LostFocus event as Command in DataGridTextColumn and can't find an example on how to use it in WPF. Can anyone help me use it as I am new to WPF.

Thank you.

My xaml looks like:

   `

    The c# code:
          public partial class Myogg : UserControl    {
          MyLogg _viewModel;
         public MyLogg()
          {
              InitializeComponent();
              _viewModel = new MyLoggUCViewModel();
              DataContext = _viewModel;
          }
        }`

Solution

  • you can use interaction triggers to do this ..

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="LostFocus">
            <i:InvokeCommandAction Command="{Binding Path=LostFocusCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>