-
Notifications
You must be signed in to change notification settings - Fork 710
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
Winui2 should have tests which ensure that code behind does not require template parts. #5525
Comments
I now have two bigger questions for the project off the back of this:
|
Yup, controls do that in a lot of areas, however it's something developers need to think about. That's also because something like this bug happen because we forgot a null check.
I think unless we write a lot of unit tests for this by hand, it will stay hard. Ideally of course, we would test every control without different templates with varying degrees of parts existing. |
We do our best to not be reliant on template parts being present, this particular example slipped through the cracks. I think adding a test that applies an empty template to all of our controls wouldn't be that hard and would likely catch a lot of these issues. @ranjeshj what do you think? @MartinZikmund or @chingucoding interested in looking into that? |
It sounds like you're saying "This is hard, but developers need to do better."
When a bug is found, it's also appropriate to ask if there are any other similar issues elsewhere that haven't been found yet...
Such a check wouldn't need to be and entirely manual process. If looking to do this, I'd write a script to walk through all current controls with a template and then iterated through each template to find named items and then create versions of the template without each named element. It's a bit of work but not overly complicated. |
Not sure how it suggested that it would be hard, I was just trying to say "Yes we can do this, we just need to think about it and not forget to add a null check". And yes it is valid to ask how things can be made more resilient, and I also proposed some way we could possibly catch this more easily.
Yes those are all valid options, the compile time checks and static analysis will probably be difficult to implement. Also, the issue is that we cannot really catch this error in one single point since we can't just stop a control from calling functions that need some control parts. Everywhere where we need template parts we need a way to check if we actually have that template.
Yes we could do this automated, however the problem is that you need to test all kind of scenarios a control can get into to check whether every state of the control respects template parts being missing.
If it is not time critical, I can take a look. Should I create an issue for tracking @StephenLPeters ? |
The best way to test would to just be blank out all the styles from all controls and then try and load them, right? Though I suppose you could have cascades, where a component is only looked at if another exists... It should catch at least some though... |
Yes, I think this would be pretty easy and catch the majority of cases. @mrlacey its not as simple as named element means the code behind requires the element. Sometimes we name an element simply to reference it other places in the template with Bindings or with Setters. This means that some of the suggestions you had would be too restrictive as there are valid scenarios for deleting named template parts. Even if a template part is used by code behind to wire something up, it can still be valid to delete that template part, and the code should be resilient to that. I definitely agree this is a place we could really improve the framework. |
I'm fine with this not being a simple thing (or at least as simple as my suggestions may have suggested)
Yay! |
I know this specific issue has been resolved, but I don't think there's a general tracking issue for improving this across the repo, eh? |
NavigationView
crashes if PaneTitleOnTopPane
is not in the control template
We can repurpose this one. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Was NavigationView crashes if PaneTitleOnTopPane is not in the control template
Describe the bug
If a custom template is used for
NavigationView
and theTextBlock
withx:Name="PaneTitleOnTopPane"
is not present, the control fails to load.Steps to reproduce the bug
Create custom template and remove
PaneTitleOnTopPane
.Expected behavior
Should not crash
Screenshots
Version Info
NuGet package version: 2.6.1
Windows app type:
Additional context
The text was updated successfully, but these errors were encountered: