Search code examples
wpfderivedselectionchanged

SelectionChanged event not firing for derived ComboBox control - WPF


I have a derived Combobox control. In Autogeneratingcolumns event, I have assigned FrameworkElemnt of derived combobox as shown below:

        var templateColumn = new DataGridTemplateColumn
            {
                CellTemplate = new DataTemplate
                {
                    VisualTree = derivedComboFrameWorkElement
                }
            };
grid.Column = CreateTemplateColumn(templateColumn);

But, the SelectionChanged event does not fires for the combobox. The funny thing is that, once I inspect the visual tree (GridCell and my ComoboBox) using WPF-Inspector, the SelectionChanged event fires. So doubting that some issue with VisualTree updates. Please help me to get this working properly.

Regards, ani


Solution

  • Good news. Issue has been identified. And the answer is, there was a PreviewMouseDown event and Focus() was called in the event. And thereby the dropdown was closed and was not available for click. I corrected the logic to solve the issue.

    To identify this kind of issues, we can make use of WPF Inspector to check visual tree and Snoop which shows all events invoked. Snoop helped me to analyse the issue. Thanks for help.

    Regards, ani