Template10:AppBarButton:带有 TextBox 的内容不允许用户输入 space
Template10: AppBarButton: Content with TextBox is not allowing user to input space
当我尝试将文本框放入 AppBarButton 元素时,模板 10 (https://github.com/Windows-XAML/Template10) 出现了一个奇怪的问题 space 键不起作用(当您按下 space 键没有任何反应你需要等待 3/4 秒才能开始工作)。但是其他所有键都在工作...
有人知道我做错了什么吗?
这是简单的 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>
@Chris W:
这就是你要我尝试的吗?添加弹出元素似乎很奇怪 no?
<AppBarButton Visibility="Visible" Width="100">
<AppBarButton.Content>
<Popup IsOpen="True" >
<TextBox Width="100" />
</Popup>
</AppBarButton.Content>
</AppBarButton>
首先,当您可以使用 Content
属性 时,这是一个奇怪的想法。但是,嘿,你是开发者,你知道你的应用程序。不是我。
好的,问题是因为 AppBarButton
清楚地捕获了 space 并处理了它。你可以用这个简单的方法克服这个问题:
<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;
}
}
很有魅力:
祝你好运!
当我尝试将文本框放入 AppBarButton 元素时,模板 10 (https://github.com/Windows-XAML/Template10) 出现了一个奇怪的问题 space 键不起作用(当您按下 space 键没有任何反应你需要等待 3/4 秒才能开始工作)。但是其他所有键都在工作...
有人知道我做错了什么吗?
这是简单的 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>
@Chris W: 这就是你要我尝试的吗?添加弹出元素似乎很奇怪 no?
<AppBarButton Visibility="Visible" Width="100">
<AppBarButton.Content>
<Popup IsOpen="True" >
<TextBox Width="100" />
</Popup>
</AppBarButton.Content>
</AppBarButton>
首先,当您可以使用 Content
属性 时,这是一个奇怪的想法。但是,嘿,你是开发者,你知道你的应用程序。不是我。
好的,问题是因为 AppBarButton
清楚地捕获了 space 并处理了它。你可以用这个简单的方法克服这个问题:
<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;
}
}
很有魅力:
祝你好运!