VisualStates are not being applied to items in a CollectionView using DataTemplates in Release Mode #9756
Labels
area-controls-collectionview
CollectionView, CarouselView, IndicatorView
area-xaml
XAML, CSS, Triggers, Behaviors
platform/android 🤖
s/needs-repro
Attach a solution or code which reproduces the issue
s/triaged
Issue has been reviewed
t/bug
Something isn't working
Description
This is a frustrating issue (which I am pretty sure is a bug) that only applies when I run our app in Release mode.
Currently, I have a dynamically rendered form. In this form, I have 2 sections. One section is a VerticalStackLayout of elements such as Editors, Entries, Pickers, and Date Pickers.
Here is an example of this section of the form:
(The SubjectFieldFilled function sets the VisualState of the element)
The second section is a CollectionView that uses an ItemTemplateSelector to dynamically assign templates as each element in the CollectionView is loaded. Elements in the CollectionView are VerticalStackLayouts that contain Labels and an Editor or Picker or Entry and so on.
Here is what the CollectionView looks like:
In addition to my form, I have created controls that apply a certain VisualState based on information in the page's overall binding. This control looks to see if a field in the form (Editor, Entry, Picker, and so on) is required to be filled out (contains data). From there, my control applies one of two VisualStates. The VisualState is either default (transparent background) or required (pink background).
Here is the code behind for setting the VisualState on a Picker (there is a different function depending on the VisualElement, but they are all setting the state to either Default or Required):
The VisualState is set for all elements when the element itself is loaded; I use the Loaded event on each item in the CollectionView. The Loaded event calls a function that sets that element's VisualState to Required or Default. After the page has loaded and each time the user inputs data into one of the form fields, the same function is called to see if that element's VisualState needs to be changed.
Here is an example of what one of the DataTemplates looks like:
(Both Loaded and SelectedIndexChanged events trigger the function that sets the VisualState of the Picker element)
And here is what our VisualStateGroupList looks like for the Picker (each element gets a VisualStateGroup list in the ResourceDictionary inside of the App.xaml page):
All of what I have described above works in Debug mode only. In Release Mode, the functions to change the state are being called, but visually the element never changes; it appears on screen with the default stylings set by MAUI. This is not a problem in the first section of my form where I am not using a CollectionView with DataTemplates.
I am wondering if this is simply a bug in trying to use VisualStates within a ColelctionView that uses a DataTemplateSelector to set items' appearance on screen.
For further reference, here are two screen captures of our app. One is how the app appears running in Debug mode and the other is how the app appears in Release mode.
Debug (stylings are applied):
Release (stylings are not applied):
Steps to Reproduce
What I expect to happen: The VisualStates of each element are set accordingly.
What happens: VisualStates of elements appear to be set, but they are not styled accordingly.the
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12
Did you find any workaround?
No
Relevant log output
No response
The text was updated successfully, but these errors were encountered: