Combobox - SelectionChanged - Input comes from User

youki 996 Reputation points
2023-01-15T15:58:15.0666667+00:00

There is no implemented flag or the right event to detect, if the input comes from a user (by keyboard and mouse)?

Depending on the CombobBox Item and a ListView selection, different pages are loaded in a frame and the selection of the ComboBox is saved. So i would have to encapsulate the page loadings. Usually there was a SelectionChangedCommitted in WinForms which would make it easier.

I can't find something. I thought maybe SelectionChangedTrigger could be something, but I don't see any difference between Always and Committed.

ComboBox Class

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
728 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,540 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
767 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dimple Rane 906 Reputation points
    2023-01-15T16:22:36.4233333+00:00

    In WPF, there is no specific event or flag to detect if an input comes from a user or not. One way to achieve this is to handle the SelectionChanged event of the ComboBox and check the Source property of the SelectionChangedEventArgs. The Source property will tell you which element raised the event, and you can use this to determine if the event was raised by the user or programmatically.

    Here is an example of how you can handle the SelectionChanged event and check the Source property:

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.Source is ComboBox)
        {
            // The event was raised by the user
        }
        else
        {
            // The event was raised programmatically
        }
    }
    
    0 comments No comments

  2. youki 996 Reputation points
    2023-01-15T17:32:44.4266667+00:00

    OK,

    I've found it.

    Adding the Tapped event to the ComboBoxItem, sigh. :)

    I tried OriginalSource (always null, there is no Source object), FocusState (not for mouse only keyboard) and a bit more.

    0 comments No comments