Height of Windows in WPF Application when Touch Keyboard appears

≡放荡痞女 提交于 2021-02-07 05:23:27

问题


I'm in the process of writing an 'touch-able' WPF Application for Windows 10. Imagine a window containing the following grid:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <TextBox Text="dsdsd"></TextBox>
    <TextBox Text="unten" Grid.Row="2" InputScope="Number"></TextBox>
</Grid>

If my application is compiled using at least .NET 4.6.2 and its window is maximized, I can touch the lower TextBox and the touch-Keyboard opens. However I'm unable to see the control because the keyboard hides it. This behaviour is differs to windows 8.x where the render-canvas size was reduced when the keyboard opened. When doing the same thing in Windows Startbar-Search field, the field does move up so I can see the input field. When opening the keyboard with maximized explorer.exe the window gets smaller.

How can I implement this behaviour in an WPF Application?

Cheers, Manuel


回答1:


From what I remember, if you've written your XAML right, it should work out of the box even when the window is maximized, but I also ran into trouble with this and ended up not fixing it (I would have wanted to, but higher management decided not to care about it).

From my investigations it seems like Microsoft fixed how Windows reacts to the presence of the touch keyoard in Windows 1903, while in 1809 and older versions, Windows does not resize the window. You can test this by maximizing Explorer and see what happens in both versions of Windows 10.

Also if your app has set WindowStyle to None, it prevents Windows from resizing your window to keep the controls visible. I talked about this in my answer here: WindowStyle None and touch input.

Also it's possible to manually reposition your controls by detecting the presence and position of the touch keyboard, check out this sample from Microsoft: TouchKeyboardNotifier

If all else fails, I think the TouchKeyboardNotifier sample code should help you achieve what you need without relying on Windows behavior.




回答2:


have you tried use when creating the windows:

    this.SizeToContent = SizeToContent.WidthAndHeight;

This will fix automatically the width and the height to fit the current size.

Source: https://docs.microsoft.com/en-us/dotnet/framework/wpf/app-development/how-to-automatically-size-a-window-to-fit-its-content



来源:https://stackoverflow.com/questions/37417988/height-of-windows-in-wpf-application-when-touch-keyboard-appears

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!