dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.04k stars 1.17k forks source link

Binding isn't updated #3050

Closed clairernovotny closed 4 years ago

clairernovotny commented 4 years ago

Evalutated expression also doesn't match datacontext image

Expected behavior: Binding is correct

Minimal repro:

It's not clear what's going on -- each time a package is loaded, it's a new PackageViewModel at the MainWindow DataContext.

miloush commented 4 years ago

That is because the two RepositoryMetadata instances are equal. Unfortunately for you, the class overrides equatability and compares only the Url, see https://github.com/NuGet/NuGet.Client/blob/f7e4a189c85fc6cfcc2d3f6b3d94079125adfe91/src/NuGet.Core/NuGet.Packaging/Core/RepositoryMetadata.cs#L68.

As far as WPF is concerned, the metadata hasn't changed and there is no binding to update.

clairernovotny commented 4 years ago

But the whole data context hierarchy is updated? Shouldn't it refresh the bindings?

clairernovotny commented 4 years ago

@nkolev92 why is RepositoryMetadata only comparing part of the data?

miloush commented 4 years ago

@clairernovotny The bindings refresh (if you put a breakpoint into EditablePackageMetadata.Repository getter, it will hit as you open the new package), but the binding sees the value is the same as before so it doesn't bother updating the target.

Your options basically are:

The class is not sealed, so you could theoretically just inherit from it and wrap the value in the property setter, with no change to your API.

Edit: or that :)

miloush commented 4 years ago

As this is by design (and the implied proposal to force-update all binding targets regardless of whether value has changed has significant performance implications and can introduce infinite loops), I assume this issue can be closed.

nkolev92 commented 4 years ago

@nkolev92 why is RepositoryMetadata only comparing part of the data?

@clairernovotny that's a bug :(

https://github.com/NuGet/NuGet.Client/commit/0e4d1b598f350b3dc675018d539114d1328189ef

Created an issue: https://github.com/NuGet/Home/issues/9613