0

I have Popup window where dynamically attaching the UserControl. Here I need to set the focus for first control. If I use:

FocusManager.FocusedElement="{Binding ElementName=txtcode}"

on UserControl the cursor not coming. Could anyone help me to set focus on first element in the UserControl.

Thanks in advance.

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
  • Try to use trigger instead http://stackoverflow.com/questions/2204063/wpf-set-focus-when-a-button-is-clicked-no-code-behind – NoWar Mar 21 '13 at 19:21

1 Answers1

0

I have just needed to do this, but not in a user control, so might not help. what I needed to do is to add the FocusManager bit in the Window tag:

<Window x:Class="xxxxx"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" FocusManager.FocusedElement="{Binding ElementName=txtcode}">

And then make sure i correctly named the control:

<TextBox Name="txtcode" Text="" />

Although I'm new to wpf, and haven't worked with user controls yet.

Charles Philip
  • 267
  • 1
  • 4
  • 8