Xamarin.forms 输入时自动弹出键盘
我在Xamain表单中使用一个网格,我想在选择事件中调用我想用wok这个词的键盘 我使用插件对话框来显示一个数字输入,但我的问题是,键盘只有在有焦点时才会显示在文本框上。我如何强制键盘弹出,以便用户不必点击字段Xamarin.forms 输入时自动弹出键盘,xamarin.forms,Xamarin.forms,我在Xamain表单中使用一个网格,我想在选择事件中调用我想用wok这个词的键盘 我使用插件对话框来显示一个数字输入,但我的问题是,键盘只有在有焦点时才会显示在文本框上。我如何强制键盘弹出,以便用户不必点击字段 new Entry() { Keyboard = Keyboard.Numeric }; var resultQty = await Plugin.DialogKit.CrossDiaglogKit.Current.GetInputTextAsy
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);
对话框工具包中的代码显示它试图将焦点放在输入字段上
<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;
}
公共任务GetInputTextAsync(字符串标题、字符串消息、字符串currentText=null、键盘=null)
{
如果(keyboard==null)keyboard=keyboard.Default;
var cts=new TaskCompletionSource();
var\u dialogView=newplugin.DialogKit.Views.InputView(标题、消息、当前文本、键盘);
_dialogView.FocusEntry();
_dialogView.Picked+=(s,o)=>{cts.SetResult(o);PopupNavigation.PopAsync();};
PushAsync(新的PopupPage{Content=\u dialogView});
返回cts.Task;
}
正如你所看到的,这是调用,但我认为这个位置是错误的,因为它在弹出到视图之前
公共空间焦点中心()
{
txtInput.Focus();
}
我做了一些测试,发现你应该在
弹出窗口之后调用FocusEntry
,强制键盘自动弹出
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;
}
private async void按钮\u已单击(对象发送方,事件参数e)
{
var resultQty=await getInputExtAsync(“Test”、$“请转到Bin,项目的可见库存。”,null,Keyboard.Numeric);
}
公共异步任务GetInputTextAsync(字符串标题、字符串消息、字符串currentText=null、键盘=null)
{
如果(keyboard==null)keyboard=keyboard.Default;
var cts=new TaskCompletionSource();
var\u dialogView=newplugin.DialogKit.Views.InputView(标题、消息、当前文本、键盘);
_dialogView.Picked+=(s,o)=>{cts.SetResult(o);PopupNavigation.PopAsync();};
等待PopupNavigation.PushAsync(新的PopupPage{Content=\u dialogView});
//弹出后调用FocusEntry
_dialogView.FocusEntry();
返回等待cts任务;
}
只需调用条目的焦点event@Jason该条目在插件对话框中,除了告诉它显示数字文本框之外,我无法控制它。@Jason我试图将其弹出,但仍然不起作用。该条目字段在rg弹出窗口中。@Jason plesae请参见我上面的编辑。@rogue39nin,因为这是一个外部对话框您可以选择:创建一个包含更改的拉取请求,并希望维护人员“快速”响应,或者你可以做公关,但在同一时间分叉的项目,做的变化,并使用一个dll,直到公关被合并,你的变化成为原来的回购的一部分。嗨,杰克,我试着使用谷歌安装板弹出窗口仍然会首先出现,所以它这样做。而用户在实际进入字段之前会弹出提示对不起,我没有理解你的意思,当我测试上述代码时,键盘会在用户进入字段之前弹出,这是你想要的吗?jack,我使用的是huweii y9 2019,但我没有使用。尽管我将代码调整为原来的代码,但弹出窗口仍然会首先出现。我删除了nuget引用,并指向我刚刚编译的本地dllinstead@rogue39nin因此,在Github上打开一个问题或创建一个pull请求将帮助您更好地解决问题第三部分是图书馆。我在iOS模拟器上测试了它,它在我这边工作。