-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Crash when using a global Style with a switch #24
Comments
@gchapeaux sorry been pretty busy with work recently, will see if i have time to look at it over the weekend. Is there a reason u need it too work via I tend to wrap most controls in a ContentView, which then allows you to only expose the properties you want access to via the rest of the app. So other developers cant change the style of a control else where. Also means you can switch out the underlying control if ever needed and remap properties to a new control. F.e. all the demo/ example switches uses this approach - https://github.com/IeuanWalker/Maui.Switch/blob/master/Demo/App/Controls/CustomSwitchExamples/IosSwitch.xaml I also recommend this approach on my other controls too - https://github.com/IeuanWalker/Maui.StateButton?tab=readme-ov-file#recomended-usage |
I have been using styles in my app from the beginning, plus I have two complemetary apps referencing the same style file, so I figured I'd be doing this for switches as well. I'll have a look at Control templates, it could be a workaround in the meantime ! Thanks for the reply ! |
THE ISSUE
I was trying to define a style for my switches in a Style.xaml file as follows :
In my page, I use my switch as follows :
When I run my project, the app crashes, and I end up having this exception :
MY INVESTIGATION
I tried to figure out on my own what the issue was, just to verify if it was on my end or from the plugin side, and it turns out the exception is raised in CustomSwitch.xaml.cs, in SizeRequestChanged, because
view.KnobFrame
andview.BackgroundFrame
are null.I tried to fix it by adding
hasLoaded
toif(bindable is not CustomSwitch view || !view.HasLoaded)
, but it caused the switches to generate in some situations with styles apparently not being applied at all :EXAMPLE REPO
Check this repository for bug reproduction.
The text was updated successfully, but these errors were encountered: