Skip to content

[WASM] Cannot alter layout of ListViewItem DataTemplate control programmatically #2744

Closed

Description

@peternary

Current behavior

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.

ListViewDataTemplate.zip

Environment

Nuget Package:
Uno.UI
Package Version(s):
2.2.0-dev.18
Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
  • Build tasks
  • Solution Templates

Visual Studio:

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

Activity

  1. added
    kind/bug
    triage/untriaged
    on Mar 4, 2020
  2. removed
    triage/untriaged
    on Mar 4, 2020
  3. davidjohnoliver commented on Mar 13, 2020

    @davidjohnoliver
    Contributor

    There are a couple of issues causing the sample provided to not display correctly:

    1. 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:
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    					xmlns:not_win="http://uno.ui/not_win"
    					xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    					mc:Ignorable="not_win">
    	<not_win:Style TargetType="local:TestClass"
    		   BasedOn="{StaticResource XamlDefaultTextBox}" />
    </ResourceDictionary>
    1. 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:
    		private void UpdateMembers()
    		{
    			....
    
    				(TestMember.Members[i].Parent as Panel)?.Children.Clear(); // Views in Members may be parented to a different item container
    				testGrid.Children.Add(TestMember.Members[i]);

    With these two workarounds, the sample behaves correctly for me on WASM.

  4. peternary commented on Mar 17, 2020

    @peternary
    Author

    Workarounds made sample work for me

  5. jeromelaban commented on Mar 18, 2020

    @jeromelaban
    Member

    Thanks @peternary. I'll be closing this issue in favor of #1766.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions