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

ObservableCollection binding not working for UWP #3816

Closed
IQBigBang opened this issue Dec 16, 2020 · 5 comments
Closed

ObservableCollection binding not working for UWP #3816

IQBigBang opened this issue Dec 16, 2020 · 5 comments
Labels
product-winui3 WinUI 3 issues

Comments

@IQBigBang
Copy link

ObservableCollection bound to a ListView does not correctly update the ListView on UWP
When a ListView is bound to an ObservableCollection with x:bind, it does not update when the collection is changed.
This bug only works for the UWP platform. Creating a Packaged Desktop project works properly.

Steps to reproduce the behavior:

  1. Create a new Blank App (WinUI in UWP)
  2. Modify the code like this:
    MainPage.xaml
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <ListView ItemsSource="{x:Bind Items, Mode=OneWay}"></ListView>
        <Button Content="Add" Click="Button_OnClick"></Button>
</StackPanel>

MainPage.xaml.cs

public sealed partial class MainPage : Page
{
    public ObservableCollection<string> Items = new ObservableCollection<string>();
    public MainPage()
    {
        this.InitializeComponent();
        Items.Add("A");
        Items.Add("B");
    }
    private void Button_OnClick(object sender, RoutedEventArgs e)
    {
        Items.Add("Next");
    }
}

Expected behavior
The list is visibly updated when the button is clicked.

Screenshots
Result on the UWP platform.
Expected result. Works on the Desktop platform.

Version Info
NuGet package version:
Microsoft.NETCore.UniversalWindowsPlatform 6.2.10
Microsoft.WinUI 3.0.0-preview3.201113.0

Windows app type:

UWP Win32
Yes No
Windows 10 version Saw the problem?
Windows 10 Home Version 20H2 Yes
Device form factor Saw the problem?
Desktop Yes

Additional context
Sorry if this is my error in the code, but I really don't understand why it works on Desktop and not on UWP so I assume it is a bug.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Dec 16, 2020
@StephenLPeters StephenLPeters added the product-winui3 WinUI 3 issues label Dec 17, 2020
@StephenLPeters
Copy link
Contributor

@stevenbrix or @Scottj1s was this an issue that was fixed through cswinrt with desktop? If so, would this be fixed with UWP being on .net 5?

@MikeHillberg FYI

@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Dec 17, 2020
@Scottj1s
Copy link
Member

Scottj1s commented Dec 17, 2020

The UWP support for WinRT in NetCore doesn't know about the new MUX interface IDs for INotifyPropertyChanged, etc. Not sure how this could work without that support.

See: microsoft/CsWinRT#331

@MikeHillberg
Copy link
Contributor

Until there's support for .Net5 in UWP, WinUI3 UWP apps need to use the INotifyCollectionChanged and INotifyPropertyChanged from the Microsoft namespace rather than the System namespace, which breaks ObservableCollection.

The Xaml Controls Gallery app has an implementation of ObservableCollection that implements the right interfaces for UWP though. You can copy it from there.

@IQBigBang
Copy link
Author

Ok thanks, but I think this should be mentioned somewhere in the documentation as I was going through the documentation for ItemsSource, which points to the INotifyCollectionChanged interface from the System namespace.

@MikeHillberg
Copy link
Contributor

Agreed, sorry it was difficult to find. I created an Issue on the doc page. (There's also info in the release notes.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product-winui3 WinUI 3 issues
Projects
None yet
Development

No branches or pull requests

4 participants