Windows 11 build 22621.1 fires a keyboard focus to slider sometimes

BillChien 6 Reputation points
2022-06-07T08:54:55.223+00:00

Hi,
My company is Microsoft Partner so I just got Windows 11 build 22621.1 for evaluation. I noticed that a slider in my GUI sometimes got black rectangle around it, as if user pressed the Tab key. Therefore I add a GotFocus callback for debug. When I execute my app, sometimes the slider got a focus message with Keyboard type, so the black rectangle shows. However, the same app always got a focus message with Pointer type with Windows 11 build 22000.194.

I have no idea why Windows 11 build 22621.1 fires keyboard focus message sometimes and it really confuses me.

Sometimes it is keyboard focus:
208990-keyboardfocus.png

Sometimes is Pointer focus:
209041-pointerfocus.png

MainPage.xaml code snippet:

    <ScrollViewer x:Name="scrollform" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" UseLayoutRounding="True" HorizontalScrollBarVisibility="Visible" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" GotFocus="Scrollform_GotFocus">  
    <Grid x:Name="mainform" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" UseLayoutRounding="True"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FlowDirection="LeftToRight" GotFocus="Mainform_GotFocus">  
              
    <TextBlock x:Name="Title_Text" HorizontalAlignment="Left" Margin="10,20,0,0" Text="Win11 22H2 AutoFocus Test" TextWrapping="Wrap" VerticalAlignment="Top" Height="52" Width="400" FontSize="24" FontWeight="Bold" FlowDirection="LeftToRight"/>  
    <TextBlock x:Name="Slider1_Text" x:Uid="Slider1_Name" HorizontalAlignment="Left" Margin="10,80,0,0" Text="Slider1" TextWrapping="Wrap" VerticalAlignment="Top" Height="36" Width="400" FontSize="15" FontWeight="Normal"/>              
    <Slider x:Name="Slider1" HorizontalAlignment="Left" Margin="10,120,0,0" VerticalAlignment="Top" Width="400" Value="3" Maximum="6" ValueChanged="Slider1_ValueChanged" Minimum="1" GotFocus="Slider1_GotFocus"/>  
    <TextBlock x:Name="Slider2_Text" x:Uid="Slider2_Name" HorizontalAlignment="Left" Margin="10,170,0,0" Text="Slider2" TextWrapping="Wrap" VerticalAlignment="Top" Height="36" Width="400" FontSize="15" FontWeight="Normal"/>  
    <Slider x:Name="Slider2" HorizontalAlignment="Left" Margin="10,210,0,0" VerticalAlignment="Top" Width="400" Maximum="7" Value="6" ValueChanged="Slider2_ValueChanged" Minimum="1" GotFocus="Slider2_GotFocus"/>  
    <!-- other GUI components are confidential so I hide it in code snippet -->  
              
    </Grid>  
    </ScrollViewer>  
Universal Windows Platform (UWP)
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,540 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,244 questions
{count} votes

4 answers

Sort by: Most helpful
  1. BillChien 6 Reputation points
    2022-06-08T01:37:22.177+00:00

    Hi Viorel-1,
    In Visual Studio, click the slider, click event hanlder list, and there is a "GotFocus", click it and it automatically adds Slider1_GotFocus() callback function. we can get focus state In this callback function, add the following code:

    void MyApp::MainPage::Slider1_GotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)  
    {  
    	String ^str = L"[Debug] Slider1 got focus from " + sender->ToString() + L"\r\n" ;  
    	OutputDebugString(str->Data());	  
    	str = L"[Debug] Focus Type = " + Slider1->FocusState.ToString() + L"\r\n";  
    	OutputDebugString(str->Data());	  
    }  
    

    Thank you.

    Bill

    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 39,381 Reputation points
    2022-06-08T07:32:23.05+00:00

    Hi there,

    As the build you are referring is Windows 11 Insider Preview Build it would be best suited to raise it to the feedback hub and share your finding to investigate further.

    You can raise feedback to the Microsoft team. The Feedback Hub app lets you tell Microsoft about any problems you run into https://support.microsoft.com/en-us/windows/send-feedback-to-microsoft-with-the-feedback-hub-app-f59187f8-8739-22d6-ba93-f66612949332

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–


  3. Ken Tucker 5,846 Reputation points
    2022-06-08T10:42:23.497+00:00

    The GotFocus event returns a RoutedEventArgs. Routed events means the event could have originated in another control. What is OriginalSource in the event args?

    https://learn.microsoft.com/en-us/dotnet/api/system.windows.routedeventargs?view=windowsdesktop-6.0

    I would have put each control in its own row in the grid rather than using margins to put the controls when you wanted

    0 comments No comments

  4. BillChien 6 Reputation points
    2022-06-10T08:34:00.557+00:00

    Hi vb2ae,
    Thanks for reply. I modified the debug log to output the RoutedEventArgs' OringalSource. As shown below:

    void MyApp::MainPage::Slider1_GotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)  
    {  
    	String ^str = L"[Debug] Slider1 got focus from sender " + sender->ToString() + L", original source " + e->OriginalSource->ToString() + "\r\n" ;  
    	OutputDebugString(str->Data());	  
    	str = L"[Debug] Focus Type = " + Slider1->FocusState.ToString() + L"\r\n";  
    	OutputDebugString(str->Data());	  
    }  
    

    Then I tried to execute & close my app 20 times. There were 8 out of 20 times keyboard focus occurred. Dbgview log:

    0.00000000	[1644] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    0.00005290	[1644] [Debug] Focus Type = Keyboard 	  
    5.18466091	[5164] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    5.18468571	[5164] [Debug] Focus Type = Pointer 	  
    11.59947681	[2304] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    11.59954453	[2304] [Debug] Focus Type = Pointer 	  
    14.04425430	[5744] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    14.04428005	[5744] [Debug] Focus Type = Pointer 	  
    16.48650742	[2432] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    16.48654175	[2432] [Debug] Focus Type = Keyboard 	  
    19.49872398	[1228] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    19.49874687	[1228] [Debug] Focus Type = Keyboard 	  
    21.83623123	[2704] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    21.83625031	[2704] [Debug] Focus Type = Keyboard 	  
    25.21125984	[5156] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    25.21128273	[5156] [Debug] Focus Type = Keyboard 	  
    27.33058167	[9168] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    27.33060074	[9168] [Debug] Focus Type = Pointer 	  
    29.95367432	[4492] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    29.95369530	[4492] [Debug] Focus Type = Pointer 	  
    39.27549362	[8104] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    39.27551270	[8104] [Debug] Focus Type = Keyboard 	  
    41.30408478	[3252] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    41.30412292	[3252] [Debug] Focus Type = Keyboard 	  
    44.46986771	[3876] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    44.46990204	[3876] [Debug] Focus Type = Pointer 	  
    47.45589066	[9468] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    47.45592880	[9468] [Debug] Focus Type = Pointer 	  
    49.18584824	[4876] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    49.18637085	[4876] [Debug] Focus Type = Pointer 	  
    51.29785538	[1628] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    51.29787827	[1628] [Debug] Focus Type = Pointer 	  
    54.07603836	[8976] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    54.07607651	[8976] [Debug] Focus Type = Pointer 	  
    57.45190430	[9716] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    57.45193100	[9716] [Debug] Focus Type = Pointer 	  
    59.87029648	[9860] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    59.87032318	[9860] [Debug] Focus Type = Pointer 	  
    61.96885681	[2700] [Debug] Slider1 got focus from sender Windows.UI.Xaml.Controls.Slider, original source Windows.UI.Xaml.Controls.Slider 	  
    61.96891022	[2700] [Debug] Focus Type = Keyboard 	  
    
    0 comments No comments