OnLostFocus virtual method not called

4 posts, 1 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 08 May 2014 Link to this post

    Hello,
    I have created a new control that inherits RadAutoCompleteBox and I need to make some work when the control lost its focus.
    I have written a OnLostFocus method that overrrides the base method, but it is unfortunately never called.
    Is this a bug?
    Patrick
  2. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 09 May 2014 Link to this post

    Hello Patrick,

    You should either override OnLostKeyboardFocus method or subscribe to the LostFocus event the following way in the constructor:

    public CustomAutoCompleteBox()
    {
        this.LostFocus += CustomAutoCompleteBox_LostFocus;
    }

    Hope this helps.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 12 May 2014 in reply to Kalin Link to this post

    Hello Kalin,
    thanks you the tip: it works.

    But it seems that there is a bug in the control code: by .NET patterns, the OnLostFocus methos MUST be called to raise the LostFocus event. So overriding the OnXXX method on an inherited class is the same as attaching to the XXX event.

    Patrick
  5. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 13 May 2014 Link to this post

    Hi Patrick,

    This is so in the particular scenario because of the WatermarkTextBox used inside of the AutoCompleteTextBox ControlTemplate. When you focus the AutoCompleteBox, the WatermarkTextBox element inside actually gets the focus and afterwards when the focus is lost the OnLostFocus method of the WatermarkTextBox is triggered.

    Hope this helps.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top