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

Update CustomSwitch.xaml.cs #22

Closed
wants to merge 1 commit into from

Conversation

gchapeaux
Copy link

I met an exception when using a Style dictionary to style CustomSwitchs, with KnobFrame and BackgroundFrame being null when SizeRequestChanged is called for the first time. Adding HasLoaded in the check at the beginning of the method seems to fix this issue.

I met an exception when using a Style dictionary to style CustomSwitchs, with KnobFrame and BackgroundFrame being null when SizeRequestChanged is called for the first time. Adding HasLoaded in the check at the beginning of the method seems to fix this issue.
@IeuanWalker
Copy link
Owner

@gchapeaux can you provide an a repo of the issue please

@gchapeaux
Copy link
Author

Hello @IeuanWalker,
I created a minimal project with the issue happening : MRE_Sandbox_9. The Style is defined in Resources > Styles, and from when I tried working on it from the main project I'm working on right now, I ended up finding the issue was caused by KnobFrame being null when SizeRequestChanged is called for the first time.

The beginning of the exception I get :

10:08:50:237	[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
10:08:50:237	[mono-rt]  ---> System.NullReferenceException: Object reference not set to an instance of an object.
10:08:50:237	[mono-rt]    at IeuanWalker.Maui.Switch.CustomSwitch.SizeRequestChanged(BindableObject bindable, Object oldValue, Object newValue)
10:08:50:237	[mono-rt]    at Microsoft.Maui.Controls.BindableObject.OnBindablePropertySet(BindableProperty property, Object original, Object value, Boolean didChange, Boolean willFirePropertyChanged) in /_/src/Controls/src/Core/BindableObject.cs:line 675
10:08:50:237	[mono-rt]    at Microsoft.Maui.Controls.Element.OnBindablePropertySet(BindableProperty property, Object original, Object value, Boolean changed, Boolean willFirePropertyChanged) in /_/src/Controls/src/Core/Element/Element.cs:line 642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants