I have simplified the problem a bit, but I need to change the style and ControlTemplate for a ListView item while still binding to the ListView ItemSource.
Here is my ListView definition:
<ListView x:Name="MyListView"
ItemsSource="{Binding ListOfStrings}"
ItemContainerStyle="{StaticResource MyListViewItemStyle}"/>
And the ItemContainerStyle:
<Style x:Key="MyListViewItemStyle" TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<DataTemplate>
<TextBlock x:Name="txtValue" Text="{Binding Mode=TwoWay}" />
</DataTemplate>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The ItemSource of the ListView is of type: List<string>
I need the TextBlock (txtValue) to display an item through the Binding to the ItemSource.
The ListView contains the correct amount of items, but how do I bind the TextBlock?
I need to do this in a WPF Universal Windows Platform application. I tested the same code in a normal WPF windows application and the code works correctly. But in the UWP application the ContentTemplate does not bind correctly.
I am sure I am missing something simple.
Try this:
Two-way binding requires Path or XPath.
The root of a Template content section cannot contain an element of type 'System.Windows.DataTemplate'. Only FrameworkElement and FrameworkContentElement types are valid.