0

I want to manually control the behavior of InputPane to prevent it from showing or hiding automatically.

enter image description here

In my page that I put its image top, I want to InputPane show as user navigate to the page and keep showing until he/she clicks on specified button and prevent it from hiding if user clicks anywhere else in the page.

Also I want to InputPane remain hidden even if user clicks on TextBox.

I already know that there are TryShow() and TryHide(), but i can't revent auto showing and hiding.

TheSETJ
  • 518
  • 9
  • 25

1 Answers1

0

The easy way to control it is by controlling focus of your TextBox. If you set IsTabStop on the TextBox to false - it won't take focus and so the SIP won't show up. If it already has focus - you'll need to move it out. If you want to display the SIP - focus the TextBox. Note that for performance reasons and also to prevent user confusion - it might make sense to use a TextBlock instead of a TextBox when the control should not be editable.

XAML

<Page
    x:Class="App18.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App18"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition
                Height="Auto" />
        </Grid.RowDefinitions>
        <TextBox
            x:Name="myTextBox"
            IsTabStop="False"
            AcceptsReturn="True"
            VerticalAlignment="Stretch"
            TextChanged="MyTextBox_OnTextChanged"/>
        <Button
            x:Name="myButton"
            Grid.Row="1"
            Click="ButtonBase_OnClick">Edit</Button>
    </Grid>
</Page>

C#

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace App18
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            myTextBox.IsTabStop = true;
            myTextBox.Focus(FocusState.Programmatic);
        }

        private void MyTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (myTextBox.Text.ToLower().Contains("done"))
            {
                myTextBox.IsTabStop = false;
                myButton.Focus(FocusState.Programmatic);
            }
        }
    }
}
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • I ran your code, TextBox takes focus on both touch and click. If I use TextBlock then I need to implement a fake cursor for it. – TheSETJ Nov 15 '16 at 06:01