简体   繁体   English

触摸键盘隐藏 UI 元素 [Windows 10 和 WPF]

[英]Touch Keyboard Hiding UI Element [Windows 10 & WPF]

I'm writing an 'touch-able' WPF Application for Windows 10 using .NET 5.我正在使用 .NET 5 为 Windows 10 编写一个“可触摸”WPF 应用程序。

I've been looking around Stack Overflow to find answer however i didn't find any, that's why I'm asking it.我一直在 Stack Overflow 上寻找答案,但我没有找到任何答案,这就是我问它的原因。

First of all, my MainWindow is not 'Maximized' and my WindowStyle is not 'None'.首先,我的 MainWindow 不是“最大化”,我的 WindowStyle 不是“无”。

<Window
    x:Class="App1234.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:prism="http://prismlibrary.com/"
    xmlns:notifications="clr-namespace:Notification.Wpf.Controls;assembly=Notifications.Wpf"
    Title="App1234"
    d:DesignHeight="1200"
    d:DesignWidth="1920"
    prism:ViewModelLocator.AutoWireViewModel="True"
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="{materialDesign:MaterialDesignFont}"
    Loaded="MainWindow_OnLoaded"
    TextElement.FontSize="14"
    TextElement.FontWeight="Medium"
    TextElement.Foreground="{DynamicResource MaterialDesignBody}"
    mc:Ignorable="d">

I can touch the lower TextBox and the touch-Keyboard opens.我可以触摸下方的文本框,然后触摸键盘打开。 However I'm unable to see the control because the keyboard hides it.但是我看不到控件,因为键盘隐藏了它。 I would like to "resize" my application in order to still see the control我想“调整”我的应用程序以便仍然看到控件

How can I implement this behaviour in an WPF Application?如何在 WPF 应用程序中实现此行为?

Thank you, Arthur谢谢你,亚瑟

UPDATE:更新:

We also launched our application as administrator without the uiAcess flag.我们还以没有 uiAcess 标志的管理员身份启动了我们的应用程序。 The solution (in addition to the reply) was to remove the administrator requirement.解决方案(除了回复)是删除管理员要求。

I am working on the same project as OP.我正在从事与 OP 相同的项目。

We found about this https://github.com/microsoft/WPF-Samples/tree/master/Input%20and%20Commands/TouchKeyboard .我们发现了这个https://github.com/microsoft/WPF-Samples/tree/master/Input%20and%20Commands/TouchKeyboard On this sample Microsoft gives some code to fix the issue for WPF with .net framework.在此示例中,Microsoft 提供了一些代码来解决 WPF 与 .net 框架的问题。

Now this works well for their usecase.现在这适用于他们的用例。 But I've been trying to implement their code with a NET 5 project.但我一直在尝试使用 NET 5 项目来实现他们的代码。 And to nobody's surprise this does not appear to be possible (the app simply crashes at the starts and overflows)不出所料,这似乎是不可能的(应用程序只是在启动时崩溃并溢出)

So does anyone know if there is a way to either make an app work with NET 5 and .net framework at the same time?那么有谁知道是否有办法让应用程序同时使用 NET 5 和 .net 框架?

Or或者

Port Microsoft's fix in Net 5 so we can use it too !将 Microsoft 的修复移植到 Net 5 中,这样我们也可以使用它!

Thx.谢谢。

Update更新

So after further re-search I found out how to fix our issue with the help of this post http://mheironimus.blogspot.com/2015/05/adding-touch-keyboard-support-to-wpf.html .因此,经过进一步的重新搜索,我发现如何在这篇文章http://mheironimus.blogspot.com/2015/05/adding-touch-keyboard-support-to-wpf.html的帮助下解决我们的问题。 and this one https://stackoverflow.com/a/57463543/14620831还有这个https://stackoverflow.com/a/57463543/14620831

    private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
var elementWithFocus = Keyboard.FocusedElement as FrameworkElement;

    if ((elementWithFocus != null) && ((e.PreviousSize.Height > e.NewSize.Height)))
    {
        elementWithFocus.BringIntoView();
    }
}

Both of these links helped understand what went wrong.这两个链接都有助于了解出了什么问题。 First the xaml had to be coded in a way that windows can resize the app when keyboard shows up, basically a scrollviewer with stackpanel inside is alright.首先,xaml 必须以 windows 可以在键盘出现时调整应用程序大小的方式进行编码,基本上一个带有堆栈面板的滚动查看器就可以了。

But this is only enough to make the window resize, this is when the code snippet allows the scrollviewer to "scroll" to the clicked element and bring it up above the virtual touch keyboard.但这仅足以使 window 调整大小,这是代码片段允许滚动查看器“滚动”到单击的元素并将其显示在虚拟触摸键盘上方的时候。

THX to the other posters, hope this post helps others too. THX到其他海报,希望这篇文章也能帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM