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

[Preview-4] winui Listview control not binding to observable collection within UWP app #4216

Closed
nzstevem opened this issue Feb 17, 2021 · 3 comments
Labels
product-winui3 WinUI 3 issues team-Markup Issue for the Markup team version-winui3preview4 WinUI 3 Preview 4 issues

Comments

@nzstevem
Copy link

Describe the bug

Not sure if this should be in ReUnion or not???

The WinUI ListView control is not binding correctly to an Observable collection in a Winui in UWP app.

The very simple code below illustrates the point.

Exactly the same code in a Winui in Desktop works fine, as does the same code in a std non winui UWP app.

Steps to reproduce the bug

Create a new Winui in UWP program and replace the following ...

MainPage.xaml

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
    <Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
    <ListView x:Name="myListView" ItemsSource="{x:Bind myItems}"></ListView>
</StackPanel>

MainPage.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;

using System.Collections.ObjectModel;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace TestOBSuwp
{
///


/// An empty page that can be used on its own or navigated to within a Frame.
///

public sealed partial class MainPage : Page
{
ObservableCollection myItems = new ObservableCollection();

    public MainPage()
    {
        this.InitializeComponent();
        myItems.Add($"{DateTime.Now.ToLongTimeString()} Initialized");
    }

    private void myButton_Click(object sender, RoutedEventArgs e)
    {
        myItems.Add($"{DateTime.Now.ToLongTimeString()}");
        myButton.Content = $"Clicked ({myItems.Count})";
    }
}

}

Expected behavior

Expect the ListView to bind to the ObservableCollection.

Screenshots

This screen snip shows std UWP, winui in desktop, and winui in UWP versions of the test code above running.

Clicking the button adds an item to the observable collection and displays the collection count in the button text. The bound ListView should display itims as they are added. The stdUWP and winui in desktop verisons (the top two) work fine. The winui in UWP version only shows the item added in the page init routine even though it is clear the items are being added to the collection. Removing the item add in the init routine results in a completely blank ListView - items are still not added from the click event.

image

Version Info

NuGet package version:

Windows app type:

UWP Win32
Windows 10 version Saw the problem?
Insider Build (21313)
Device form factor Saw the problem?
Desktop

Additional context

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Feb 17, 2021
@StephenLPeters StephenLPeters added version-winui3preview4 WinUI 3 Preview 4 issues product-winui3 WinUI 3 issues labels Feb 19, 2021
@StephenLPeters
Copy link
Contributor

I think this is because UWP is not currently building against .net5 @stevenbrix can you confirm?

@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Feb 19, 2021
@anawishnoff
Copy link
Contributor

@nzstevem, @StephenLPeters is correct - please see a more detailed explanation of this in our release notes, in the "Known Issues" section under "For C# UWP apps" : Preview 4 Release Notes

@krschau krschau added the team-Markup Issue for the Markup team label Jul 19, 2021
@bpulliam
Copy link
Contributor

UWP is no longer supported by WinUI 3. If you can repro the issue on current builds without UWP, please reactivate or open a new issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product-winui3 WinUI 3 issues team-Markup Issue for the Markup team version-winui3preview4 WinUI 3 Preview 4 issues
Projects
None yet
Development

No branches or pull requests

5 participants