1

I have a simple xaml page with one TextBox and a RichTextBlock. Inside that RichTextBlock there are some InlineUIContainers.

But when the user presses a button, I remove through code an InlineUIContainer. This goes well, but each time this is done, the TextBox that is on the page get's focus! Resulting in the touch keyboard popping up. Anyone an idea why this is happening? Or how I can prevent this? I can't set the IsTabStop, because the user still has to be able to fill something in if needed.

I'm working on the Windows Phone part of a WinRT Universal app

Some code, but the actual removal is done in the Attached Dependency Property It's the KeywordsInput textbox that get's the focus after each removal

<TextBox x:Uid="Search_KeywordsInput" x:Name="SearchKeywordsInput"
           Text="{Binding KeywordsInput, Mode=TwoWay}" />

<RichTextBlock Grid.Row="4"
           Margin="0,9.5,0,0"
           IsTextSelectionEnabled="False"
           dependencyProperties:RichTextBlockTagCloud.Command="{Binding SelectedTagFilterCommand}"
           dependencyProperties:RichTextBlockTagCloud.TagItems="{Binding SelectedFilters, Mode=TwoWay}">
<Paragraph x:Name="TagsFilters" />

foreach (InlineUIContainer container in buttonsToRemove)
    tagParagraph.Inlines.Remove(container);
Depechie
  • 6,102
  • 24
  • 46

2 Answers2

2

Have you try to set IsTabStop=False on Button, so clicking button doesn't steal RichTextBox focus.

slow coder
  • 42
  • 7
0

If you remove the focused control then the focus will move to a valid control. In this case, the next control found is your TextBox. If you park the focus on a benign (non-text) control before removing the focussed button then the keyboard won't trigger.

Depending on your overall layout you may be able to set the focus to the page, you may have another button which would make sense, or you could add a non-editable control to the tab order.

Rob Caplan - MSFT
  • 21,714
  • 3
  • 32
  • 54
  • What I find weird is that the first time you open a page on windows phone said textbox won't get focus, so why should it get focus now? Other problem is that the removal is done inside the attached prop. There I have no knowledge of other controls on the page... But I can try to do something with messaging or events to move the focus... – Depechie Jan 12 '15 at 08:45