I have an ObservableCollection that I try to bind to a list of text boxes. The textboxes do show but the content of the text does not.
The XAML:
<Grid>
<Grid.RowDefinitions >
<RowDefinition />
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding Path=ListOfMessages}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Message, ElementName=ListOfMessages}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
The Code:
In the ViewModel:
public ObservableCollection<ApplicationLog> ListOfMessages { get; set; }
In the Model:
public class ApplicationLog
{
public string Code { get; set; }
public string Message { get; set; }
}
When I run this, the app shows the text boxes (for example 4 text boxes, one below the other), but the text in the text boxes (ie the Message
property) is not shown. I think my Binding expression for the Text Box is wrong.
Context: I am new to XAML and WPF. More generally: how does one debug Binding issues similar to this one.
Thanks.