xamarin.forms - 输入时自动弹出键盘
问题描述
我在 Xamain 表单中使用网格,我想在选择事件上调用我认为做这个词 wok 的键盘。
我正在使用插件对话工具包来显示一个数字条目,但我的问题是键盘仅在具有焦点时才显示在文本框上我如何强制键盘出现以便用户不必单击该字段。
new Entry()
{
Keyboard = Keyboard.Numeric
};
var resultQty = await Plugin.DialogKit.CrossDiaglogKit.Current.GetInputTextAsync("Test", $"Please goto Bin {item.BinName} , and enter the visible stock of the item." + item.Name, null, Keyboard.Numeric);
Dialog kit 中的代码显示它试图将焦点放在输入字段上。
<ContentView.Content>
<StackLayout Padding="10" BackgroundColor="White" VerticalOptions="CenterAndExpand" Margin="25">
<Label FontAttributes="Bold" FontSize="Large" Text="{Binding Title}"/>
<Label FontSize="Large" Text="{Binding Message}"/>
<Entry x:Name="txtInput" Keyboard="{Binding Keyboard}"/>
<StackLayout Margin="10" Orientation="Horizontal">
<Button Text="{Binding OK}" Clicked="Confirm_Clicked" HorizontalOptions="FillAndExpand"/>
<Button Text="{Binding Cancel}" Clicked="Cancel_Clicked" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</StackLayout>
</ContentView.Content>
您将在此处看到对话工具包调用上述几个
public Task<string> GetInputTextAsync(string title, string message,string currentText = null, Keyboard keyboard = null)
{
if (keyboard == null) keyboard = Keyboard.Default;
var cts = new TaskCompletionSource<string>();
var _dialogView = new Plugin.DialogKit.Views.InputView(title, message,currentText,keyboard);
_dialogView.FocusEntry();
_dialogView.Picked += (s, o) => { cts.SetResult(o); PopupNavigation.PopAsync(); };
PopupNavigation.PushAsync(new PopupPage { Content = _dialogView });
return cts.Task;
}
正如您所看到的那样,它正在调用,但我认为它的位置是错误的,因为它在它弹出到视图之前。
公共无效 FocusEntry() { txtInput.Focus(); }
</p>
解决方案
我做了一些测试,发现你应该调用FocusEntry
afterPopUp
来强制键盘自动出现。
private async void Button_Clicked(object sender, EventArgs e)
{
var resultQty = await GetInputTextAsync("Test", $"Please goto Bin, the visible stock of the item.", null, Keyboard.Numeric);
}
public async Task<string> GetInputTextAsync(string title, string message, string currentText = null, Keyboard keyboard = null)
{
if (keyboard == null) keyboard = Keyboard.Default;
var cts = new TaskCompletionSource<string>();
var _dialogView = new Plugin.DialogKit.Views.InputView(title, message, currentText, keyboard);
_dialogView.Picked += (s, o) => { cts.SetResult(o); PopupNavigation.PopAsync(); };
await PopupNavigation.PushAsync(new PopupPage { Content = _dialogView });
//Call the FocusEntry after PopUp
_dialogView.FocusEntry();
return await cts.Task;
}
推荐阅读
- c# - 根据服务类中的条件向客户端发送 401/403 错误
- angular - 可拖动事件到 FullCalendar
- nlp - 如何在 spaCy 中打印多个标签?
- flutter - 如何在颤动中将焦点转移到另一个文本表单字段
- c++ - TYPED_TEST 用于类模板
- kubernetes - 不同 Kubernetes 集群中的 Hazelcast 节点之间的数据是否强一致?
- javascript - 在范围输入中,当最小值和最大值相等时,幻灯片应该只是一个点?
- python - 在 GCP 中使用 Cloud Functions 抓取页面并将其加载到 BigQuery
- compilation - 尝试使用 ncurses 运行 C 代码时出现编译和链接错误
- jmeter - JMeter摘要报告中两个字段的含义 - 测试和总计