In XAML, I have an ItemsControl
binded to an ObservableCollection<string>
.
Inside it as ItemControl.ItemTemplate
, a TextBox binded to the string.
<ItemsControl ItemsSource="{x:Bind ViewModel.MyNames, Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Mode=TwoWay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
public ObservableCollection<string> MyNames = new ObservableCollection<string> {"aa", "bb", "cc" };
If I edit any text box I receive the Error:
Error
Cannot save value from target back to source. Binding: Path='' DataItem='Windows.Foundation.IReference`1<String>';
target element is 'Windows.UI.Xaml.Controls.TextBox' (Name='null');
target property is 'Text' (type 'String')
How do I link the text box to the string value? While respecting MVVM pattern of course. x:Bind
I don't know if it can bind to the default value given by ItemsSource
.