2016-11-13 74 views
0

我想手动控制InputPane的行为以防止它自动显示或隐藏。UWP - 如何防止InputPane自动显示和隐藏

enter image description here

在我的网页,我把自己的形象之上,我想InputPane显示为用户导航到该页面,并保持显示,直到他/她点击指定的按钮,并防止它隐藏,如果用户点击任何地方否则在页面中。

另外我想InputPane保持隐藏,即使用户点击TextBox。

我已经知道有TryShow()和TryHide(),但我不能避免自动显示和隐藏。

+0

据我所知,这是不可能更改默认隐藏行为。 –

+0

@ ElvisXia-MSFT感谢您的重播。 – TheSETJ

+0

@jerrynixon你有什么建议吗? – TheSETJ

回答

0

控制它的简单方法是通过控制你的焦点TextBox。如果您将TextBox上的IsTabStop设置为false,则它不会占用焦点,因此SIP不会显示。如果它已经有了重点 - 你需要将它移出。如果你想显示SIP - 重点TextBox。请注意,出于性能原因,也为了防止用户混淆 - 当控件不可编辑时,使用TextBlock而不是TextBox可能是有意义的。

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); 
      } 
     } 
    } 
} 
+0

我运行了你的代码,TextBox将焦点放在了触摸和点击上。 如果我使用TextBlock,那么我需要为它实现一个假的光标。 – TheSETJ