Open halfninja opened 2 days ago
To do nothing when there's no match, or if this usage isn't allowed, to output a meaningful error that explains the mistake.
OnPlatform follows ternary operator logic. It always needs to return a value. In this case it's a null
.
It's still expected to return null as a default in some contexts.
We should at least generate a diagnostic error, which can be optionally disabled.
Thanks both - I did add OnPlatform.Default to fix it as soon as I realised the error, and understood that it was essentially returning null. Could simply be a docs thing - which does have a default case in the example snippets, but perhaps explicitly stating that you likely need to match all platforms in XAML to avoid inserting a null style (though I understand it's not just for styles)
Describe the bug
I'd written a style with an override for when the window is maximised in Windows:
Works fine on Windows. When I start the app on Macos (or probably any other platform) I get this ominous exception
To Reproduce
Define in Application.Styles an OnPlatform element that doesn't match the current platform
Expected behavior
To do nothing when there's no match, or if this usage isn't allowed, to output a meaningful error that explains the mistake. I can add a default match with an unused style in it as a workaround.
Avalonia version
11.2.0
OS
Windows, macOS
Additional context
No response