microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.29k stars 675 forks source link

WinUI Multibinding Support #8334

Open JoeTomkinson opened 1 year ago

JoeTomkinson commented 1 year ago

Proposal: Multibinding Support

Summary

formerly UWP supported multibinding even as a predecessor to WPF. Multi-binding support was available for both command and converter parameters. This particular feature appears to have already been ported over to MAUI. WinUI3 still appears to lack this capability.

Rationale

It's useful to have multi-binding because it allows developers to create complex hierarchical data-templates for dynamic content generation whilst being able to pass bindings up and down between parent and child elements.

sigmarsson commented 6 months ago

Yes releasing in 1.5 would be feasible ?

GuildOfCalamity commented 5 months ago

Is this ever coming to WindowsAppSDK? I'm currently using 1.5.240311000 and there is still no support for <MultiBinding> or IMultiValueConverter

legistek commented 4 months ago

As the original author of MultiBinding support in Xamarin Forms I would very much like to see this in WinUI. :)

The implementation was quite simple and if not for so much of WinUI being sealed or otherwise non-extensible it would be a very easy thing to implement in managed code.

legistek commented 4 months ago

Until this is added natively:

https://github.com/peter0302/WinUI.Redemption/

GuildOfCalamity commented 4 months ago

@legistek will definitely check this out, thank you... at least someone recognizes the shortcomings with WinUI

JoeTomkinson commented 4 months ago

Until this is added natively:

https://github.com/peter0302/WinUI.Redemption/

That's interesting, I'll take a look at some point over the weekend, thank you for your effort on that.

PRs from Forks ok if there's any additional value I can add in there?

legistek commented 4 months ago

@GuildOfCalamity yeah, finally being able to see the code explains a lot though. The entire projection system from native to managed is batty and I'm convinced explains at least 50% of the frustration. One also wonders how many seemingly senseless restrictions and counterproductive performance tweaks we're still living with that were just done for the Surface RT. Visually the framework is amazing but I wish they'd have burned the RT codebase and started from scratch for Windows 10 with something more sensibly balanced between native and managed like WPF was. Alas. But anyway now that it's decoupled from the OS they can be more liberal with changes that previously would've required an OS update, so I really hope they start tackling more of these longstanding issues now. Maybe my little project can help things along.

@JoeTomkinson please by all means.

GuildOfCalamity commented 4 months ago

@JoeTomkinson What baffles me is the fact that this was already working in UWP... why remove it?

legistek commented 4 months ago

I don't think MultiBinding ever existed in Metro or UWP. MultiBinding works with a MAUI app running atop UWP (or any other platform current or future), but it's still implemented at the MAUI layer. So if you're coming from MAUI (or WPF) to WinUI it looks like it was taken out but it wasn't ever there to begin with.

Incidentally WPF's implementation is completely different from the MAUI implementation and is probably 100x the lines of code.

I always thought my solution in XF was on the hackish-side, just as this new one definitely is, but then again if you look at the guts of MAUI/XF a whole lot of it fits that description. I imagine a native C++ implementation that used the WinUI internals would take a different approach, but who knows.

GuildOfCalamity commented 4 months ago

@legistek Well, at any rate, your code works. I had an issue where I needed to pass two date objects in an ObservableCollection source for Multibinding color switching. One date is the creation time and the other is the updated time; the further the dates get apart from one another the color then changes to match their difference.

contextfree commented 4 months ago

I don't think MultiBinding ever existed in Metro or UWP

or Silverlight (which was the codebase that Metro/UWP/WinUI3 was originally forked from)

legistek commented 4 months ago

Wait, was Silverlight written in native C++? I always assumed it was the same codebase as WPF. But it explains A LOT if that was the foundation for Metro.

(Sidenote - If Silverlight was always C++ why in heaven's name didn't they port it to WASM/Mono instead of killing it??).

contextfree commented 4 months ago

Yeah, Silverlight was a rewrite of the WPF core layout engine into C++, with a C# managed API layer on top. (Metro/WinRT XAML kept the layout engine and replaced that API layer with a WinRT one.)

GuildOfCalamity commented 4 months ago

If anyone needs to refer to my test of @legistek multibinding support: TabApp

GuildOfCalamity commented 4 months ago

@legistek Just curious, but in MultiBinding.cs you note that the GrowableArray<DependencyProperty> _proxyProps is not thread safe; could a ConcurrentBag (or other Concurrent model) be used for this, or would that be unnecessary?

legistek commented 4 months ago

@GuildOfCalamity oh well MultiBinding as a whole is ultimately threadsafe because I lock _proxyProps before using it, which is basically what any Concurrent collection would do. That was just a note so no one else forgot to lock it before using it. In any case I wanted the underlying collection to just be an array because of how infrequently items will be added vs. retrieved. Also items need to be easily retrieved by index for the whole "fungible AttachedProperty's" thing to work.