[英]Set focus to UserControl (c# UWP)
I have a problem setting focus to my UserControl.我在将焦点设置到我的 UserControl 时遇到问题。 I want the control to gain focus whenever it is clicked (pointer pressed event).
我希望控件在单击时获得焦点(指针按下事件)。
Here's the control:这是控制:
<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>
Whenever pointer is pressed I call this.Focus(FocusState.Pointer) in the code.每当按下指针时,我都会在代码中调用 this.Focus(FocusState.Pointer)。 However the method always returns false (fails to set FocusState, which remains as Unfocused).
然而,该方法总是返回 false(无法设置 FocusState,它保持为 Unfocused)。 What should I do to set focus to my user control?
我应该怎么做才能将焦点设置到我的用户控件上?
try add IsTapEnabled="True" IsTabStop="True"尝试添加 IsTapEnabled="True" IsTabStop="True"
https://codedocu.com/Details?d=1595&a=9&f=181&l=0&v=d&t=UWP:-Focus-and-Keyboard-Events-with-IsTabStop-=-true https://codedocu.com/Details?d=1595&a=9&f=181&l=0&v=d&t=UWP:-Focus-and-Keyboard-Events-with-IsTabStop-=-true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.