Fluent.TextBox focus problem

Jun 9, 2011 at 9:44 AM

I have a Fluent Text Box defined in the XAML <Fluent:TextBox Name="rbTxtBoxName" ...>

I want to set the cursor (focus) to it when a button is clicked. So far, I have been unsuccessful.

I have tried the following in the button click event

rbTxtBoxName.Focus(); --> doesnt work

also

Keyboard.Focus(rbTxtBoxName); -->doesn't work

also

rbTxtBoxName.RaiseEvent(new RoutedEventArgs(Fluent.TextBox.Mous

eDoubleClickEvent)); -->doesn't work

Any help will be appreciate it. Thanks
Jun 14, 2011 at 4:32 PM

Has anyone experienced this? or has any ideas?
Thanks

Jun 16, 2011 at 4:42 AM

try               txtLastName.Focus(); where txtLastName is the name you set in XAML portion 

for example:

XAML:

<TextBox Grid.Column="1" Grid.Row="0"  Margin="5,0,0,0" VerticalAlignment="Stretch" x:Name="txtLastName"  />

C#:

       private void buttonCreateNewContact_Click(object sender, RoutedEventArgs e)
        {
                 txtStatus.Text = "Management Mode - Create New Contact";                
                DoEvents();
                txtLastName.Focus();
         }

Jun 16, 2011 at 10:13 PM

Hi Adam,

Thanks for your input. Setting the textbox.focus() was the first thing I tried which it did not work.

Setting the focus in wpf text boxes this way works fine, but not if it is a fluent:textbox.  This Fluent:TextBox resides in the Fluent:Ribbon.

I have tried some other ways, like the ones mentioned on my first post, but nothing seems to work!

Thanks

Jun 17, 2011 at 5:22 AM

Why use a Fluent textbox over a wpf textbox?

Jul 30, 2011 at 12:12 PM

I had the same issue and find a solution to it. I'm not sure if this solution will always work but for now it's fine:

I discovered that after setting the focus via code when I press the Tab Key the focus will be in the textbox. Maybe the Fluent Textbox consists of the icon in front of it an the textbox itself. Setting the focus brings the focus only to some invisible control and sending a TAB brings it to the textbox.

In my code I use the following snippet:

_SearchText.Focus();
Keyboard.Focus(_SearchText);

TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
_SearchText.MoveFocus(request);

Where _SearchText is a Fluent TextBox