Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6909845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:44:26+00:00 2026-05-27T08:44:26+00:00

I have ComboBox inside StackPanel. I am using MVVM and try to bind ‘GotFocus’

  • 0

I have ComboBox inside StackPanel. I am using MVVM and try to bind ‘GotFocus’ event Command to Command in ViewModel but when I Click on ‘ComboBox’, it don’t work (It don’t call Command in ViewModel) but if I move that ‘ComboBox’ out of ‘StackPanel’ it’s working properly.

How can I fire event from 'CombBox' inside 'StackPanel' in MVVM?

  <StackPanel x:Name="StackPanel" Grid.Column="2" Grid.Row="6">
    <ComboBox x:Name="ComboBox" ItemsSource="{Binding Values}">
      <i:Interaction.Triggers>
        <i:EventTrigger EventName="GotFocus">
          <cmd:EventToCommand Command="{Binding Path=GotFocusCommand}"/>
        </i:EventTrigger>
      </i:Interaction.Triggers>
    </ComboBox>
  </StackPanel>

ViewModel's code is:

public ViewModelCommand GotFocusCommand { get; set; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:44:27+00:00Added an answer on May 27, 2026 at 8:44 am

    ////Change your tag from EventToCommand to InvokeCommandAction

    <StackPanel x:Name="StackPanel" Grid.Column="2" Grid.Row="6">
    <ComboBox x:Name="ComboBox" ItemsSource="{Binding Values}">
      <i:Interaction.Triggers>
        <i:EventTrigger EventName="GotFocus">
          <cmd:InvokeCommandAction="{Binding Path=GotFocusCommand}"/>
        </i:EventTrigger>
      </i:Interaction.Triggers>
    </ComboBox>
    

    ////Then, I use my commands this way in my view model:

      private ICommand _GotFocusCommand;
        public ICommand GotFocusCommand
        {
            get
            {
                if (_GotFocusCommand == null)
                {
                    _GotFocusCommand =
                        new RelayCommand(
                            param => GotFocusCommand_Executed(),
                            GotFocusCommand_CanExecute
                         );
                }
    
                return _GotFocusCommand;
            }
        }
    

    ////RelayCommandClass.cs:

    public class RelayCommand : ICommand
    {
    private Action _handler;
    public RelayCommand(Action handler)
    {
        _handler = handler;
    }
    
    private bool _isEnabled;
    public bool IsEnabled
    {
        get { return _isEnabled; }
        set
        {
            if (value != _isEnabled)
            {
                _isEnabled = value;
                if (CanExecuteChanged != null)
                {
                    CanExecuteChanged(this, EventArgs.Empty);
                }
            }
        }
    }
    
    public bool CanExecute(object parameter)
    {
        return IsEnabled;
    }
    
    public event EventHandler CanExecuteChanged;
    
    public void Execute(object parameter)
    {
        _handler();
    }
    }
    

    ////Finally, you can create an event in your view model:

    private void GotFocusCommand_Executed()
        {
            //DoSomething here
        }
    
    private bool GotFocusCommand_CanExecute()
        {
            return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF/MVVM (using MVVM-Light) app setup with a ComboBox that is inside
I have ContentControls like ComboBox and TextBox inside of a Grid or a StackPanel.
I have a display problem when I try to use a ajax combobox inside
I have a ComboBox inside of a cell of a DataGridView Row on a
I have a combobox that passes along values in text, but they can have
I have a usercontrol which has a combobox inside it. This UserControl is the
I have a silverlight combobox inside of a dataform as follows: <dataControls:DataForm x:Name=newScheduleMasterForm Height=350
I need to have an event fired whenever Enter is pressed inside of the
I have a simple combobox with a checkbox inside as such: <ComboBox Height=23 HorizontalAlignment=Left
I have a Panel control. And inside the panel users can add combobox's, textbox's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.