Set the focus on a TextBox in WPF XAML

You can use the FocusManager.FocusedElement attached property for this purpose. Here’s a piece of code that set the focus to TxtB by default. <StackPanel Orientation=”Vertical” FocusManager.FocusedElement=”{Binding ElementName=TxtB}”> <TextBox x:Name=”TxtA” Text=”A” /> <TextBox x:Name=”TxtB” Text=”B” /> </StackPanel> You can also use TxtB.Focus() in your code-behind if you don’t want to do this in XAML.

Is there a cross-browser solution for monitoring when the document.activeElement changes?

While @James’s answer above is correct. I’ve added more details to make it a completely working solution along with the use of focus event too. <html> <body> <input type=”text” id=”Text1″ name =”Text1″ value=””/> <input type=”text” id=”Text2″ name =”Text2″ value=””/> <SELECT><OPTION>ASDASD</OPTION><OPTION>A232</OPTION></SELECT> <INPUT TYPE=”CHECKBOX” id=”Check1″/> <INPUT type=”TEXT” id=”text3″/> <input type=”radio”/> <div id=”console”> </div> <textarea id=”textarea1″> </textarea> <script> … Read more

How to change listview selected row backcolor even when focus on another control?

What you describe works exactly as expected, assuming that you’ve set the HideSelection property of the ListView control to False. Here’s a screenshot for demonstration purposes. I created a blank project, added a ListView control and a TextBox control to a form, added some sample items to the ListView, set its view to “Details” (although … Read more

Panel not getting focus

The Panel class was designed as container, it avoids taking the focus so a child control will always get it. You’ll need some surgery to fix that. I threw in the code to get cursor key strokes in the KeyDown event as well: using System; using System.Drawing; using System.Windows.Forms; class SelectablePanel : Panel { public … Read more

WPF – Remove focus when clicking outside of a textbox

Rather than adding new control to window, I think you should give your Grid a name and react to the MouseDown event on your window, moving the focus to the Grid itself. Something like this: <Window x:Class=”WpfApplication1.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”Window1″ Height=”412″ Width=”569″ MouseDown=”Window_MouseDown” Name=”window1″> <Grid ShowGridLines=”False” Background=”#01FFFFFF” KeyDown=”Grid_KeyDown” Name=”grid1″ Focusable=”True”> <TextBox Width=”120″ Margin=”117,61,0,0″ Name=”textBox1″ VerticalAlignment=”Top” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)