将焦点设置为UserControl(c#UWP) [英] Set focus to UserControl (c# UWP)

查看:77
本文介绍了将焦点设置为UserControl(c#UWP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将焦点设置到UserControl时遇到问题.我希望控件在每次单击时都获得焦点(指针按下事件).

I have a problem setting focus to my UserControl. I want the control to gain focus whenever it is clicked (pointer pressed event).

这是控件:

<UserControl
x:Class="MyApp.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="100"
d:DesignWidth="160"
Canvas.ZIndex="10"  
IsEnabled="True"
IsFocusEngagementEnabled="True"
AllowFocusOnInteraction="True"
UseSystemFocusVisuals="True">
...
</UserControl>

每当按下指针时,我都会在代码中调用this.Focus(FocusState.Pointer).但是,该方法始终返回false(无法设置FocusState,仍然保留不专心).我该怎么做才能将焦点设置到我的用户控件上?

Whenever pointer is pressed I call this.Focus(FocusState.Pointer) in the code. However the method always returns false (fails to set FocusState, which remains as Unfocused). What should I do to set focus to my user control?

推荐答案

尝试添加IsTapEnabled ="True" IsTabStop ="True"

try add IsTapEnabled="True" IsTabStop="True"

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆