When I create a Resource, we specify a DataType inside it:
<Window.Resources> <DataTemplate x:Key="StudentView" DataType="this:StudentData"> <TextBox Text="{Binding Path=StudentFirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" /> <TextBox Text="{Binding Path=StudentGradePointAverage}" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" /> </DataTemplate> <Window.Resources>
And when binding:
<ItemsControl ItemsSource="{Binding TheStudents}" ItemTemplate="{StaticResource StudentView}">
So why do we use DataType even if I delete DatType, my example works fine. Is this a limitation of certain types that may be inside a DataTemplete?
But I tried binding one of the TextBoxs to the garbage size (not present in the View-Model), and it works great!
source share