如何让 UWP 不聚焦,文本光标在外面?

问题描述 投票:0回答:1

我有一个具有手写功能的 UWP 应用程序,在带触摸屏的笔记本电脑上进行测试。 手写完成后,识别出的文字会暂时存储在一个文本块中。 然后我期望做的是,文本块中的文本应该传输到文本光标的位置,可能是记事本,浏览器的搜索框,聊天室等

但是,当我在我的应用程序上执行手写时,焦点将被带到应用程序中,并且文本光标会消失。一般来说,一旦我touch我的应用程序,焦点总是会立即获得。这是我要解决的关键问题。

WPF中,我可以通过将WS_EX_NOACTIVATE设置为HWND来实现我的目标,如下所示 发布。 场景是一样的。但在 UWP 中,该方法无法应用,因为 UWP 不支持 HWND 的概念。

(顺便说一句,我需要构建 UWP 的原因是 Windows.UI.Xaml.Controls.HandwritingView,WPF 不支持它。)

此外,我还尝试了UserControls的一些属性。 我已经为项目中的所有相关控件设置了AllowFocusOnInteraction="False"Page-Grid-Textbox-HandwritingView, 并尝试了一些想法 post,即使场景不同
不幸的是,所有这些都不起作用。一旦我触摸我的应用程序,焦点仍然存在。

我被困在这里好几天了。感谢您提前提出任何想法。

下面是我的代码示例:

<Page
x:Class="UWPtest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPtest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="1440"
Height="1300"
AllowFocusOnInteraction="False"  
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
    <TextBox x:Name="tbHandWriteView" HorizontalAlignment="Center" Margin="0,0,0,0" FontSize="60" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="1300" Height="1200" FontFamily="Segoe UI"/>
</Grid>
    public MainPage()
    {
        this.InitializeComponent();

        tbHandWriteView.IsHandwritingViewEnabled = true;
        tbHandWriteView.HandwritingView.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch | Windows.UI.Core.CoreInputDeviceTypes.Pen;
        tbHandWriteView.HandwritingView.PlacementAlignment = HandwritingPanelPlacementAlignment.TopLeft;
        tbHandWriteView.HandwritingView.Width = 1000;
        tbHandWriteView.HandwritingView.Height = 1000;
        tbHandWriteView.HandwritingView.Visibility = Visibility.Visible;


        this.AllowFocusOnInteraction = false;
        tbHandWriteView.AllowFocusOnInteraction = false;
        tbHandWriteView.HandwritingView.AllowFocusOnInteraction = false;

        tbHandWriteView.HandwritingView.TryOpen();
    }

下面是我遇到的问题:

  1. 我触摸记事本,文本光标将在记事本中。
  2. 我触摸我的 UWP 应用程序进行手写。
  3. 焦点被app拿走,记事本文字光标消失

video recorded here

c# uwp focus uwp-xaml text-cursor
1个回答
0
投票

我明白你想要达到的目标。但这是 UWP 应用程序的预期行为。单击 UWP 应用时,UWP 应用将获得焦点。在 UWP 应用程序中没有 API 可以做你想做的事。

© www.soinside.com 2019 - 2024. All rights reserved.