WPF TextBox Focus

Posted by Jezz on Stack Overflow See other posts from Stack Overflow or by Jezz
Published on 2010-06-03T13:05:35Z Indexed on 2010/06/03 14:54 UTC
Read the original article Hit count: 252

Filed under:

I am setting focus on a Textbox like this:

<DockPanel
        Margin="0,0,0,0"
        LastChildFill="True"
        FocusManager.FocusedElement="{Binding ElementName=messengerTextToSend}">
        <ListBox
            x:Name="messengerLabelParticipants"
            DockPanel.Dock="Top" Height="79" Margin="0,1,0,0" Padding="0"
            Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0"
            AllowDrop="True"
            ItemsSource="{Binding Path=involvedUsers}" ItemTemplate="{StaticResource chatParticipants}" Tag="{Binding Path=chatSessionID}"
            Drop="participantList_Drop" DragEnter="participantList_DragEnter" DragLeave="messengerLabelParticipants_DragLeave">
        </ListBox>
        <TextBox
            x:Name="messengerTextToSend"
            Focusable="True"
            Margin="10,0,10,10"
            DockPanel.Dock="Bottom" Height="100"
            Tag="{Binding Path=.}"
            KeyUp="messengerTextToSend_KeyUp"
            Cursor="IBeam"
            Style="{StaticResource messengerTextBoxSendText}"/>
        <ScrollViewer 
            x:Name="messengerScroller" 
            Template="{DynamicResource ScrollViewerControlTemplate1}" 
            ScrollChanged="messengerScroller_ScrollChanged" Loaded="messengerScroller_Loaded"
            Margin="0,10,0,10">
            <ListBox
                x:Name="messengerListMessages"
                Margin="10,0,0,0" Padding="0" 
                Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0"
                IsSynchronizedWithCurrentItem="True"
                ItemsSource="{Binding Path=messages}" ItemTemplateSelector="{StaticResource messageTemplateSelector}">
            </ListBox>
        </ScrollViewer>
    </DockPanel>

However, when the page load, although the Textbox visually appears to have focus, the cursor is static and I have to manually either click on the Textbox or tab to it in order to start typing. I'm not sure what I'm doing wrong but I've tried every setting, inclduing setting it in the code to get it working. Any assistance would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about wpf