Skip to content
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

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

Closed
1 of 12 tasks
peternary opened this issue Mar 4, 2020 · 3 comments
Closed
1 of 12 tasks
Assignees
Labels
kind/bug Something isn't working

Comments

@peternary
Copy link

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?

@peternary peternary added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Mar 4, 2020
@jeromelaban jeromelaban removed the triage/untriaged Indicates an issue requires triaging or verification label Mar 4, 2020
@davidjohnoliver davidjohnoliver self-assigned this Mar 12, 2020
@davidjohnoliver
Copy link
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 ([Epic] Wasm/Skia 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.

@peternary
Copy link
Author

Workarounds made sample work for me

@jeromelaban
Copy link
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
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants