GetFocusScope/GetIsFocusScope inconsistency
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
.NET 6.0.15
Docs for [FocusManager.GetFocusScope](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager.getfocusscope?view=windowsdesktop-7.0&viewFallbackFrom=net-6.0) say
> Determines the closest ancestor of the specified element that has [IsFocusScope](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager.isfocusscope?view=windowsdesktop-7.0#system-windows-input-focusmanager-isfocusscope) set to true.
However, I have a control `c` and when I call `FocusManager.GetIsFocusScope(GetFocusScope(c))`, the returned value is false. Either the documentation is incorrect, or the implementation.
In my xaml I have:
```xaml
```
And in the codebehind:
```c#
private void UIElement_OnGotFocus(object sender, RoutedEventArgs e)
{
var c = (Control)sender;
var fs = FocusManager.GetFocusScope(c);
var wasScope = FocusManager.GetIsFocusScope(fs);
if (!wasScope)
{
throw new InvalidOperationException();
}
}
```
When the textbox gets focus, the exception is always thrown.
I would be very happy to provide more information on my code, the visual tree and so on, but I'm not sure what is salient. I don't call [FocusManager.SetIsFocusScope](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager.setisfocusscope?view=windowsdesktop-7.0&viewFallbackFrom=net-6.0) anywhere in the program.
Contributor guide
Assessment
This issue has not been assessed yet.