Click here to Skip to main content
13,048,035 members (70,314 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Guys,

I'm working with WPF Popup, in the popup, I have a TextBox there but I couldn't hit any text there. No keys are working for that.

Does any one know what the problem is?

Can you please suggest me solution to this problem?

<Popup Name="popup1">
                    <RowDefinition Height="40"></RowDefinition>
                    <RowDefinition Height="40"></RowDefinition>
                <Grid Grid.Row="0">
                        <ColumnDefinition Width="100"></ColumnDefinition>
                    <TextBox Name="desc" Grid.Column="0" AcceptsReturn="True" IsReadOnly="False" MaxLength="500" IsEnabled="True" Focusable="True"></TextBox>
            <Grid Grid.Row="1">
                        <ColumnDefinition Width="100"></ColumnDefinition>
                    <ComboBox Grid.Column="0" 

Posted 20-Apr-11 0:03am
Updated 20-Apr-11 1:40am
Venkatesh Mookkan 20-Apr-11 6:05am
Can you post the XAML (if necessary codebehind) so that it is easy for us to figure out the problem?
Henry Minute 20-Apr-11 6:33am
Is the TextBox Enabled?
Is it ReadOnly?
Srinivas39 20-Apr-11 6:42am
It's enabled and not readonly
Venkatesh Mookkan 20-Apr-11 6:58am
Just post the XAML. It would easy to help you.
Srinivas39 20-Apr-11 7:17am
please find the code given
Prerak Patel 20-Apr-11 6:56am
Don't you like to share code?
Srinivas39 20-Apr-11 7:08am
<Popup Name="popup1"><GRID><GRID.ROWDEFINITIONS> <ROWDEFINITION height="40"></ROWDEFINITION></GRID.ROWDEFINITIONS><GRID grid.row="0"><GRID.COLUMNDEFINITIONS> <COLUMNDEFINITION width="100"></COLUMNDEFINITION></GRID.COLUMNDEFINITIONS><TEXTBOX name="desc" grid.column="0" acceptsreturn="True" isreadonly="False" maxlength="500" isenabled="True" focusable="True"> </TEXTBOX></GRID></GRID></Popup>
Srinivas39 20-Apr-11 7:13am
please find the code above, this is from an XAML file
BobJanova 20-Apr-11 7:38am
Are you giving the textbox focus? Is there some control which is hogging the focus, or overlaying the text box so you can't select it?
Srinivas39 20-Apr-11 7:42am
I made focusable is true too, But when i keep my mouse over the textbox and select, it's not been selecting and no focus :(
Srinivas39 20-Apr-11 7:43am
nothing on the popup, is selectable including labels... is there any issue with popup?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Why are you defining grid rows and columns when you only have one of each? That's just pointless. Also, the AcceptsReturn property is only useful if it's a multi-line text box.

Finally, your problem is caused by the fact that you're trying to use the Popup control in a way that is nt intended. The hwnd that represents the popup has the style WS_EX_NOACTIVATE, meaning the popup can't gain the focus. The reason for that is that the Popup control is used for tooltips and other static displays (like images), NOT for input. You should therefore carefully reconsider whether or not your design intentions are even appropriate.

If you INSIST on pursuing this course (and I can't recommend strongly enough that you do it a different way), you have to use interop services to set the popup window as the foreground window:

[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public static void ActivatePopup(Popup popup)
    //try to get a handle on the popup itself (via its child)
    HwndSource source = (HwndSource)PresentationSource.FromVisual(popup.Child);
    IntPtr handle = source.Handle;
    //activate the popup
BobJanova 20-Apr-11 13:20pm
This I did not know. Good answer, 5.
SAKryukov 20-Apr-11 18:09pm
Quite logical, my 5.
pdsulliv 13-Jun-13 18:14pm
Backdoor, Nice solution.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


I believe you can use such popups for more than just tooltips, that's the whole point of WPF, you can do anything.

Except get the darn textboxes to accept keystrokes !.

Okay so I trawled around a fair bit to find a solution and saw lots of references to Plumbing in the keyboard events from the hosting windows form to your WPF contained window by calling


But I couldn't get this to work with a wpf popup, I just couldn't get the "Window" and I tried a few things.

Anyway I accidentally found a work around. If you have a panel from which you have a popup, and you have a textbox on that panel, and you click into it and type in some text, then you trigger your popup to come up - youre textbox will work and be plumbed in. Its as if the text box on teh base control triggers all the plumbing.

Kind of hard to explain, but here's the code
        <stackpanel background="LightSeaGreen" orientation="Horizontal">
            <textbox x:name="mytextbox" width="0" xmlns:x="#unknown" />
            <textblock x:name="blessme" text="This is the popup button." mouseenter="popupUC_Loaded" xmlns:x="#unknown">
                    <eventtrigger routedevent="Mouse.MouseUp">
                                    <booleananimationusingkeyframes storyboard.targetname="ConnectPopup">
                                             <discretebooleankeyframe keytime="00:00:00" value="True" /> 
            <popup x:name="ConnectPopup" placementtarget="{Binding ElementName=ConnectPopupTrigger}" xmlns:x="#unknown">
                                   PopupAnimation="Slide" AllowsTransparency="True" StaysOpen="False">
                <border margin="2 2,0,3" borderthickness="1" borderbrush="DarkSlateGray">
                    <!-- The connection section, username, password, connect button -->
                    <stackpanel orientation="Vertical" margin="0,0,3,3">
                        <stackpanel orientation="Horizontal">
                            <label width="70">User Name:</label>
                            <textbox text="{Binding FXAllUserName}" width="120" margin="1" />
                        <stackpanel orientation="Horizontal">
                            <label width="70">Password:</label>
                            <passwordbox x:name="mypassword" width="120" margin="1" />

void popupUC_Loaded(object sender, RoutedEventArgs e)

UIElement element = mytextbox as UIElement;

if (element != null)
Boolean success = element.Focus(); //Always returns false and doesn't take focus.


All I had to do programtically was get the hidden text box to gain focuss for an instant and the textbox in your popup would contain text.

Try it without the hidden text box "mytextbox" and you'll see it doesn't work.

Ok a poor work around, but just means you add a zero width text box and a quick callback and it all works.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100