Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationView.IsBackButtonVisible throws "value out of range" exception #8521

Closed
sjb-sjb opened this issue Jun 2, 2023 · 10 comments
Closed
Labels
bug Something isn't working

Comments

@sjb-sjb
Copy link

sjb-sjb commented Jun 2, 2023

Describe the bug

I frequently encounter a "value out of range" exception when assigning to NavigationView.IsBackButtonVisible.

Steps to reproduce the bug

Assign a value to IsBackButtonVisible in code.

Expected behavior

Should not throw

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.3.1: 1.3.230502000

Windows version

No response

Additional context

No response

@sjb-sjb sjb-sjb added the bug Something isn't working label Jun 2, 2023
@sjb-sjb sjb-sjb changed the title NavigationView throws "value out of range" exception NavigationView.IsBackButtonVisible throws "value out of range" exception Jun 7, 2023
@sjb-sjb
Copy link
Author

sjb-sjb commented Jun 7, 2023

I get the same exception when assigning NavigationViewBackButtonVisible.Collapsed to a DependencyProperty that is registered with type NavigationViewBackButtonVisible, using the DependencyObject.SetValue method. The dependency property is bound OneWay with x:Bind to the IsBackButtonVisible property of the NavigationView.

I am using net6.0-windows10.0.19041.0

The exception is:

System.ArgumentException
HResult=0x80070057
Message=Value does not fall within the expected range.
Source=WinRT.Runtime
StackTrace:
at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.Controls.INavigationView2Methods.set_IsBackButtonVisible(IObjectReference _obj, NavigationViewBackButtonVisible value)
at MyCustomViewer.XamlBindingSetters.Set_Microsoft_UI_Xaml_Controls_NavigationView_IsBackButtonVisible(NavigationView obj, NavigationViewBackButtonVisible value) in [...]

@Jay-o-Way
Copy link
Contributor

What is the value you set?

@sjb-sjb
Copy link
Author

sjb-sjb commented Jun 20, 2023

I set it to Collapsed. I set it when the value was not already Collapsed. When the debugger breaks on the exception and I test the value it says that it is now set to Collapsed in the NavigationView. I am still narrowing it down but it appears that I set it from the constructor of a containing control (but after InitializeComponent)

@Jay-o-Way
Copy link
Contributor

@sjb-sjb could you share a few line of codes to show exactly what's being assigned? Maybe it's a case of variable type, or something? Like, the string "Collapsed" may not be accepted, but Visibility.Collapsed will?

@sjb-sjb
Copy link
Author

sjb-sjb commented Jul 1, 2023

I tried to narrow this down but without success. For the time being I have put an if test around the assignment to only allow the assignment if the assigned value is different from the current value. I am not sure this will work but will keep you posted if I find out anything further.

@sjb-sjb
Copy link
Author

sjb-sjb commented Jul 29, 2023

The most I've got at the moment is this stack trace info:

at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr) at ABI.Microsoft.UI.Xaml.Controls.INavigationView2Methods.set_IsBackButtonVisible(IObjectReference _obj, NavigationViewBackButtonVisible value)

Commenting that "IsBackButtonVisible" suggests boolean type while the actual type is an enum. Maybe there is an incorrectly declared variable somewhere in WinRT? I have checked and I am assigning the enum type.

@Jay-o-Way
Copy link
Contributor

Jay-o-Way commented Jul 29, 2023

Commenting that "IsBackButtonVisible" suggests boolean type while the actual type is an enum

Okay. A Boolean does sound obvious. Where did you see it is a enum?
Could it be that you're mixing Visibility with IsVisible?

@sjb-sjb
Copy link
Author

sjb-sjb commented Jul 29, 2023

It shows the enum in intellisense and also, of course, in the docs: https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.navigationview.isbackbuttonvisible?view=windows-app-sdk-1.3

Besides, how complicated can INavigationView2Methods.set_IsBackButtonVisible be? A reasonable chance that the problem is obvious if ine looks there.

@Jay-o-Way
Copy link
Contributor

Jay-o-Way commented Jul 29, 2023

You're right, this looks like a bug. The enum is also mentioned https://learn.microsoft.com/windows/apps/design/controls/navigationview#backwards-navigation
Have you tried using 0 or 1? Otherwise, apart from the general advice to update everything that can possibly be related, I don't know...

@sjb-sjb
Copy link
Author

sjb-sjb commented Aug 3, 2023

I was using a control template for the NavigationViewItemPresenter that was out of date. Not sure that this was the cause but it did cause some other problems. Given the difficulty reproducing, I suggest we close this.

@sjb-sjb sjb-sjb closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants