locked
IsEditable ComboBox LostFocus called initially instead of GotFocus event while focus ComboBox WPF RRS feed

  • Question

  • I have checked WPF ComboBox with IsEditable as true. 

    While focus ComboBox, LostFocus event called first time, then GotFocus have called. 

    How to resolve this?

    Code :

    XAML:

     <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel>
                <ComboBox Height="40" Width="200"
                          Margin="10"
                          GotFocus="ComboBox_GotFocus"
                      LostFocus="ComboBox_LostFocus" IsEditable="True"/>
                <TextBox Text="TextBox" Height="30" 
                         Margin="10"
                         Width="200" />
            </StackPanel>
         
            <StackPanel Grid.Column="1">
                <Button Content="Clear" Width="100" Height="50" Margin="10"
                        Click="Button_Click"/>
                <ListView x:Name="listview"  Margin="10" Height="300">
    
                </ListView>
            </StackPanel>
           
        </Grid>

     C#:

      private void ComboBox_GotFocus(object sender, RoutedEventArgs e)
            {
                listview.Items.Add("GotFocus");
            }
    
            private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
            {
                listview.Items.Add("LostFocus");
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                listview.Items.Clear();
            }

    


    Thanks, Muneesh.

    Wednesday, May 13, 2020 1:04 PM

All replies

  • Hi Muneesh Kumar,

    Thank you for posting here.

    According to your description, your question is more related to WPF. Therefore, it will be more appropriate to ask your question in  WPF forum.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.
    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 14, 2020 1:27 AM