2016-01-22 76 views
3

当我试图将文本框放在AppBarButton元素中时,模板10(https://github.com/Windows-XAML/Template10)出现一个奇怪的问题,空格键不起作用(当您按下空格键没有任何反应,你需要等待3/4秒才能开始工作)。然而,每一个其他的关键是在工作...Template10:AppBarButton:TextBox中的内容不允许用户输入空格

任何人都知道我做错了什么?

下面是简单的XAML代码:

<AppBarButton Icon="Find" Visibility="Visible"> 
    <AppBarButton.Content> 
     <TextBox Width="100" /> 
    </AppBarButton.Content> 
</AppBarButton> 

我得到了同样的问题有:

<AppBarButton Visibility="Visible"> 
       <AppBarButton.Content> 
        <TextBox Width="100" /> 
       </AppBarButton.Content> 
      </AppBarButton> 

@克里斯宽: 这是你要我什么尝试?添加一个弹出式元素no似乎很奇怪吗?

<AppBarButton Visibility="Visible" Width="100"> 
       <AppBarButton.Content> 
        <Popup IsOpen="True" > 
         <TextBox Width="100" /> 
        </Popup> 
       </AppBarButton.Content> 
      </AppBarButton> 
+1

所以从[文档](https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.appbarbutton.aspx) - **如果图标是设置。**所以我不确定这里的警告是什么,那么将它放在附加的PopUp而不是内容中怎么样? –

+0

我已更新我的帖子,但是即使我没有设置图标属性也会得到相同的问题 – Damien

+0

顺便说一句:你的想法将它放在弹出窗口中确实有用谢谢=) – Damien

回答

2

首先,当Content属性可用于您时,这是一个奇怪的想法。但是,嘿,你是开发者,你知道你的应用程序。不是我。

好的,问题是因为AppBarButton清楚地捕捉空间并处理它。你可以用这种简单的方法解决这个问题:

<controls:PageHeader Content="Main Page"> 
    <AppBarButton Width="250" Padding="0"> 
     <AppBarButton.Template> 
      <ControlTemplate> 
       <TextBox Width="250" Height="32" Margin="0,8,0,0" 
          KeyUp="TextBox_KeyUp" /> 
      </ControlTemplate> 
     </AppBarButton.Template> 
    </AppBarButton> 
    <AppBarButton Icon="Find" /> 
</controls:PageHeader> 

然后该处理程序:

private void TextBox_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) 
{ 
    if (e.Key == Windows.System.VirtualKey.Space) 
    { 
     var textBox = sender as TextBox; 
     textBox.SelectionStart = (textBox.Text += " ").Length; 
    } 
} 

就像一个魅力:

enter image description here

祝您好运!

+0

作品像一个魅力,谢谢 – Damien

+0

这正是我一直在寻找。谢谢。 – FlyingMaverick

相关问题