I'm using Linq To Sql to fill up a listbox with Segment objects, where Segment is designer created/ORM generated class.
<Window x:Class="ICTemplates.Window1"
...
xmlns:local="clr-namespace:ICTemplates"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="MyTemplate">
<!-- <DataTemplate DataType="x:Type local:Segment"> -->
// some stuff in here
</DataTemplate>
</Window.Resources>
<ListView x:Name="tvwSegments" ItemsSource="{Binding}" ItemTemplate="{StaticResource MyTemplate}" MaxHeight="200"/>
// code-behind
var queryResults = from segment in tblSegments
where segment.id <= iTemplateSid
select segment;
tvwSegments.DataContext = queryResults;
This works.
However if I used a Typed Data Template (by replacing the x:Key with the DataType attribute on the template, the items all show up with ICTemplates.Segment
(the ToString() return value)
The concept is that it should pick up the data template automatically if the Type matches. Can someone spot the mistake here?