You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[WASM] Cannot alter layout of ListViewItem DataTemplate control programmatically #2744
In WASM attempting to programmatically alter the layout of an instance of a ListViewItem can fail entirely.
Expected behavior
Should be able to update layout programmatically as in UWP.
How to reproduce it (as minimally and precisely as possible)
Load the attached project in UWP and observe that ListViewItems have their layout altered during runtime, adding ColumnDefinitions to a grid as needed.
Load the attached project in WASM and observe that the ListView does not appear to render at all, and there are console errors regarding the state of the grid.
There are a couple of issues causing the sample provided to not display correctly:
The custom view subclassed from TextBox has no Style (and hence no template) because DefaultStyleKey isn't taken into account. This will be fixed when Styles and Xaml resources compatibility #1766 is merged. For now the workaround is to manually add the default style:
In the MyUserControl.UpdateMembers()method, where the views from theMembersproperty of the bound item are added to theGrid`, an error occurs because the views are still parented to the previous item container that they were bound to. This comes from the way Uno handles item updates, which will be improved when full observable collection support is added to WASM (♥️ ListView improvements #234), but in any case it's safer not to rely on an item being rebound to its previous container. To handle the possibility that the children may be bound to a previous parent, add the following line immediately before trying to add the views:
privatevoidUpdateMembers(){....(TestMember.Members[i].ParentasPanel)?.Children.Clear();// Views in Members may be parented to a different item containertestGrid.Children.Add(TestMember.Members[i]);
With these two workarounds, the sample behaves correctly for me on WASM.
Activity
davidjohnoliver commentedon Mar 13, 2020
There are a couple of issues causing the sample provided to not display correctly:
TextBoxhas no Style (and hence no template) becauseDefaultStyleKeyisn't taken into account. This will be fixed when Styles and Xaml resources compatibility #1766 is merged. For now the workaround is to manually add the default style:MyUserControl.UpdateMembers()method, where the views from theMembersproperty of the bound item are added to theGrid`, an error occurs because the views are still parented to the previous item container that they were bound to. This comes from the way Uno handles item updates, which will be improved when full observable collection support is added to WASM (♥️ListViewimprovements #234), but in any case it's safer not to rely on an item being rebound to its previous container. To handle the possibility that the children may be bound to a previous parent, add the following line immediately before trying to add the views:With these two workarounds, the sample behaves correctly for me on WASM.
peternary commentedon Mar 17, 2020
Workarounds made sample work for me
jeromelaban commentedon Mar 18, 2020
Thanks @peternary. I'll be closing this issue in favor of #1766.