Skip to content

Commit a875635

Browse files
authored
Update readme file.
1 parent d28a387 commit a875635

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

README.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ The included UI elements are:
770770
- [BindableLabel](#bindablelabel)
771771
- [BindableTextField](#bindabletextfield)
772772
- [BindableButton](#bindablebutton)
773+
- [BindableDropdownField](#bindabledropdownfield)
773774
- [BindableListView](#bindablelistview)
774775
- [BindableScrollView](#bindablescrollview)
775776
- [BindingContextProvider](#bindingcontextprovider)
@@ -842,42 +843,35 @@ To pass a parameter to the viewmodel, see the [ParameterValueConverter](#paramet
842843

843844
#### BindableDropdownField
844845

845-
The `BindableDropdownField` allows you to work with dropdown. To set the binding of the selected value, you need to write `binding-selected-item-path`, and to set the binding of all dropdown elements, you need to use `binding-items-source-path`.
846-
Moreover, you can set them independently of each other.
847-
848-
The following example demonstrates how to bind to a collection of strings with `BindableDropdownField`.
849-
850-
In XML, you need to write the following:
851-
852-
```xml
853-
<ui:UXML xmlns:uitk="UnityMvvmToolkit.UITK.BindableUIElements" ...>
854-
<uitk:BindableDropdownField binding-selected-item-path="SelectedValue" binding-items-source-path="Choices" />
855-
</ui:UXML>
856-
```
857-
And in the C# class the following:
846+
The `BindableDropdownField` allows the user to pick a choice from a list of options. The `BindingSelectedItemPath` attribute is optional.
858847

859848
```csharp
860849
public class DropdownFieldViewModel : IBindingContext
861850
{
862851
public DropdownFieldViewModel()
863852
{
864-
TextValues = new ReadOnlyProperty<ObservableCollection<string>>(new ObservableCollection<string>()
853+
var items = new ObservableCollection<string>
865854
{
866-
"Value1",
867-
"Value2",
868-
"Value3"
869-
});
870-
871-
SelectedValue = new Property<string>();
872-
SelectedValue.Value = "Value1";
855+
"Value 1",
856+
"Value 2",
857+
"Value 3"
858+
};
859+
860+
Items = new ReadOnlyProperty<ObservableCollection<string>>(items);
861+
SelectedItem = new Property<string>("Value 1");
873862
}
874-
875-
public IProperty<string> SelectedValue { get; }
876-
877-
public IReadOnlyProperty<ObservableCollection<string>> Choices { get; }
863+
864+
public IReadOnlyProperty<ObservableCollection<string>> Items { get; }
865+
public IProperty<string> SelectedItem { get; }
878866
}
879867
```
880868

869+
```xml
870+
<ui:UXML xmlns:uitk="UnityMvvmToolkit.UITK.BindableUIElements" ...>
871+
<uitk:BindableDropdownField binding-items-source-path="Items" binding-selected-item-path="SelectedItem" />
872+
</ui:UXML>
873+
```
874+
881875
#### BindableListView
882876

883877
The `BindableListView` control is the most efficient way to create lists. It uses virtualization and creates VisualElements only for visible items. Use the `binding-items-source-path` of the `BindableListView` to bind to an `ObservableCollection`.

0 commit comments

Comments
 (0)