Textbox will not remain in focus on when in Menu

3 posts, 1 answers
  1. Tom
    Tom avatar
    38 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2013 Link to this post

    I have added a text box into a menu with the following code. 

    <telerik:RadMenuItem x:Name="EmployeeLookupMenuItem" StaysOpenOnClick="True" >
         <telerik:RadMenuItem.Header>
              <StackPanel>
                   <telerik:RadWatermarkTextBox Name="EmployeeLookupTextBox" KeyUp="EmployeeLookupTextBox_KeyUp" WatermarkContent="Employee ID" Width="100" />
              </StackPanel>
         </telerik:RadMenuItem.Header>
    </telerik:RadMenuItem>

    The text box appears however when I click in it to type something it will only stay in focus while the mouse button is down. As soon as I release the mouse button it loses focus and I can no longer type in the box.

    Why can I not type in the textbox?
  2. Answer
    Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 29 Jan 2013 Link to this post

    Hi Tom,

    I've tested your problem and the issue is reproduced only when you click at the end of RadWaterMarkTextBox - if you click directly in the center, you will be able to type. The problem is that at the end of the control there isn't a TextBox which handles the mouse events if you click in the center. So these mouse events are catched by RadMenuItem and treated as click. This is the expected behavior. If you want to write in RadWaterMarkTextBox, no matter where you've clicked, you should "catch" MouseLeftButtonUp event before RadMenuItem. Here is how to achieve this:
    <telerik:RadMenuItem Header="Item 1">
        <telerik:RadMenuItem x:Name="EmployeeLookupMenuItem" StaysOpenOnClick="True">
            <telerik:RadMenuItem.Header>
                <StackPanel>
                    <telerik:RadWatermarkTextBox Name="EmployeeLookupTextBox" KeyUp="EmployeeLookupTextBox_KeyUp_1" WatermarkContent="Employee ID" Width="100" MouseLeftButtonUp="EmployeeLookupTextBox_MouseLeftButtonUp_1"/>
                </StackPanel>
            </telerik:RadMenuItem.Header>
        </telerik:RadMenuItem>
    </telerik:RadMenuItem>

    And in code behind:
    private void EmployeeLookupTextBox_KeyUp_1(object sender, KeyEventArgs e)
    {
        e.Handled = true;
    }
     
    private void EmployeeLookupTextBox_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e)
    {
        e.Handled = true;
    }

    Please test it from your side and inform me if you still have any problems or concerns.

    Greetings,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Tom
    Tom avatar
    38 posts
    Member since:
    Mar 2007

    Posted 29 Jan 2013 Link to this post

    This worked. Thank you.
Back to Top