Xamarin.forms Xamarin表单-在UWP、Android和iOS中防止键盘显示在输入焦点上

Xamarin.forms Xamarin表单-在UWP、Android和iOS中防止键盘显示在输入焦点上,xamarin.forms,keyboard,xamarin.uwp,Xamarin.forms,Keyboard,Xamarin.uwp,在Xamarin.Forms中,我可以通过创建自定义渲染器并使用针对Android的ShowSoftInputInfo和针对iOS的InputView,防止在Entry view接收焦点时键盘弹出 但是在UWP中我可以用什么来防止它呢 防止在进入视图接收焦点时弹出键盘 UWP有直接的API支持隐藏和显示。您可以调用TryHide方法来隐藏键盘。对于xamarin,您可以使用DependencyService来接近它。有关更多信息,请参阅以下代码 接口 public interface IKeyb

在Xamarin.Forms中,我可以通过创建自定义渲染器并使用针对Android的ShowSoftInputInfo和针对iOS的InputView,防止在Entry view接收焦点时键盘弹出

但是在UWP中我可以用什么来防止它呢

防止在进入视图接收焦点时弹出键盘

UWP有直接的API支持隐藏和显示。您可以调用
TryHide
方法来隐藏键盘。对于xamarin,您可以使用
DependencyService
来接近它。有关更多信息,请参阅以下代码

接口

public interface IKeyboard
{
    void HideKeyboard();
    void ShowKeyboard();
    void RegisterAction(Action<object, KeyboardState> callback);
}
public enum KeyboardState
{
    Hide,
    Show
}
DependencyService.Get<IKeyboard>().RegisterAction((s,e)=> {
    if (e == KeyboardState.Show)
    {
        var keyboard = s as IKeyboard;
        keyboard.HideKeyboard();
    }
});
公共接口IKeyboard
{
无效隐藏板();
void ShowKeyboard();
无效注册表操作(操作回调);
}
公共枚举键盘状态
{
隐藏
显示
}
KeyboardImplementation.cs

public class KeyboardImplementation : IKeyboard
{
    private InputPane _inputPane;
    private Action<object, KeyboardState> action;

    public KeyboardImplementation()
    {
        _inputPane = InputPane.GetForCurrentView();
        _inputPane.Showing += OnInputPaneShowing;
        _inputPane.Hiding += OnInputPaneHiding;
    }
    public void HideKeyboard()
    {
        _inputPane.TryHide();
    }
    public void ShowKeyboard()
    {
        _inputPane.TryShow();
    }
    public void RegisterAction(Action<object, KeyboardState> callback)
    {
        action = callback;
    }

    private void OnInputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs args)
    {
        action(this, KeyboardState.Hide);
    }

    private void OnInputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
    {
        action(this, KeyboardState.Show);
    }
}
公共类键盘实现:IKeyboard
{
专用输入窗格_输入窗格;
私人行动;
公共键盘实现()
{
_inputPane=inputPane.GetForCurrentView();
_inputPane.Showing+=OnInputPaneShow;
_inputPane.Hiding+=OnInputPaneHiding;
}
公共无效隐藏板()
{
_inputPane.TryHide();
}
公用键盘()
{
_inputPane.TryShow();
}
公共无效注册表操作(操作回调)
{
动作=回调;
}
InputPaneHiding上的私有无效(InputPane发送方、InputPaneVisibilityEventArgs参数)
{
动作(这个,KeyboardState.Hide);
}
InputPaneShow上的私有无效(InputPane发送方、InputPaneVisibilityEventArgs参数)
{
动作(这个,KeyboardState.Show);
}
}
用法

public interface IKeyboard
{
    void HideKeyboard();
    void ShowKeyboard();
    void RegisterAction(Action<object, KeyboardState> callback);
}
public enum KeyboardState
{
    Hide,
    Show
}
DependencyService.Get<IKeyboard>().RegisterAction((s,e)=> {
    if (e == KeyboardState.Show)
    {
        var keyboard = s as IKeyboard;
        keyboard.HideKeyboard();
    }
});
DependencyService.Get().RegisterAction((s,e)=>{
if(e==KeyboardState.Show)
{
var键盘=s作为IKeyboard;
键盘。隐藏板();
}
});

@NicoShu感谢Nico,但此解决方案将显示软键盘,然后将其隐藏。我正在寻找一个解决方案,不显示键盘时,所有的条目收到焦点。我发现了一篇文章,解释了如何使用自定义条目渲染器和ShowSoftInputInfocus for Android以及iOS上的InputView来实现这一点,但自定义渲染器也会这样做,键盘仍然会短暂显示,然后消失。和你的建议一样,这会让事情变得更糟,因为用户现在不断地弹出键盘,然后自己消失。是的,这个解决方案只是用来隐藏键盘,它是全局设置。可以灵活地在界面中设置退订方式。uwp中还有另一个解决方案,请参考此。如果你认为这是可行的,我可以帮你为xamarin
Entry
control制作一个插件。谢谢@NicoShu,但我不是在寻找隐藏键盘的解决方案。我正在寻找解决方案,以防止键盘显示完全一旦自定义条目收到焦点。弹出键盘,然后隐藏它会让事情变得更糟。是的,我知道,但目前,xaml控件没有这样的属性。如果您确实需要此功能,请随时发布。您提供的链接根本没有要求Xamarin表单功能的区域??Hi@cd491415您是否找到任何解决方案来防止Xamarin表单uwp的输入焦点出现软键盘?