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

Is it possible to bind multiple data to a component? #27

Open
wang-er-s opened this issue Aug 15, 2019 · 1 comment
Open

Is it possible to bind multiple data to a component? #27

wang-er-s opened this issue Aug 15, 2019 · 1 comment

Comments

@wang-er-s
Copy link

in lua mvvm,i can do this,second parameter is a table,third para is a decorator,make a suit style let view show
self:bind("num", {"inventory.current_used", "inventory.capacity"},function(current_used, capacity)
    return ("%d/%d"):format(current_used, capacity)
end) --  "5/100"

in c#,I didn't expect any good solution. do you have any good idea? pls tell me ! thanks

@ryantrem
Copy link
Collaborator

ugui-mvvm is largely modeled after XAML bindings. Back in WPF XAML, we had something to achieve this called a MultiBinding, which aggregated multiple regular Bindings, and then specified an IMultiValueConverter. If ugui-mvvm had something like this, then in your example above, the second parameter would map to the multiple aggregated bindings, and the third parameter would map to the multi-converter.

I think this could be a good approach for ugui-mvvm, but would definitely require some work. I think something like this would make sense:

  1. Factor out some of the core logic in the PropertyBinding class.
  2. Create a MultiPropertyBinding class that has a collection of the factored out stuff from PropertyBinding. Imagine in the inspector having a collection of elements that look similar to what we see in PropertyBinding today, where each element has a binding source, a binding target, and optionally a converter. Additionally, it would have a target property just like PropertyBinding.
  3. Introduce an IMultiValueConverter interface, and have it be a required property on the MultiPropertyBinding. This is the thing that would combine multiple property values into a single output value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants