LibraStack / UnityMvvmToolkit

Brings data-binding to your Unity project
MIT License
469 stars 27 forks source link

Add BindingContextProvider #17

Closed ChebanovDD closed 1 year ago

ChebanovDD commented 1 year ago

To automatically provide a custom BindingContext for child elements.

public class TestItemViewModel : ICollectionItem
{
    [Observable] 
    private readonly IProperty<string> _name = new Property<string>();

    ...
}
public class TestViewModel : IBindingContext
{
    [Observable]
    private readonly IProperty<TestItemViewModel> _selectedItem;
}
[UxmlElement]
public partial class TestItemViewModelProvider : BindingContextProvider<TestItemViewModel>
{
}
<ui:UXML ...>
    <BindableUIElements.TestItemViewModelProvider binding-context-path="SelectedItem">
        <UnityMvvmToolkit.UITK.BindableUIElements.BindableLabel binding-text-path="Name" />
    </BindableUIElements.TestItemViewModelProvider>
</ui:UXML>