Need to get XamlRoot of the CalenderView opened by Focusing into CalenderDatePicker in WinUI3

Vignesh Govindhan 26 Reputation points
2021-12-06T06:30:28.32+00:00

The purpose of Getting the XamlRoot is to move the focusable element inside CalenderView. To move the focus we need to get the current focused element FocusManager.GetFocusedElement() which requires XamlRoot for WinUI3. So, How to get the XamlRoot of the CalenderView ?. If not, is there any better way to manipulate the focus within CalenderView

This one doesn't work as XamlRoot returns the CalenderDatePicker's frame.

private void CalendarDatePicker_Opened(object sender, object e)
{
   FocusManager.TryMoveFocus(FocusNavigationDirection.Previous, new FindNextElementOptions() { SearchRoot = (FocusManager.GetFocusedElement((sender as FrameworkElement).XamlRoot) as FrameworkElement) });
}

Exception for the above code is "Value doesn't fall in expected range"

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
784 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.