Sim*_*ons 4 wpf xaml datatemplate
在创建资源时,我们在其中指定DataType:
<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>
Run Code Online (Sandbox Code Playgroud)
虽然绑定:
<ItemsControl ItemsSource="{Binding TheStudents}"
ItemTemplate="{StaticResource StudentView}">
Run Code Online (Sandbox Code Playgroud)
那么为什么我们使用DataType,即使我删除了DatType,我的样本运行正常.是否限制某些类型,可以在DataTemplete中?
但我尝试将其中一个TextBox与垃圾值绑定(View-Model中不存在),它运行正常!
H.B*_*.B. 12
的DataType
是隐含的应用程序,即使你删除掉x:Key
你不需要引用它在ItemsControl.ItemTemplate
为例子.阅读文档.
此属性与Style类的TargetType属性非常相似.在不指定x:Key的情况下将此属性设置为数据类型时,DataTemplate将自动应用于该类型的数据对象.请注意,执行此操作时,将隐式设置x:Key.因此,如果为此DataTemplate指定x:Key值,则覆盖隐式x:Key,并且不会自动应用DataTemplate.
归档时间: |
|
查看次数: |
7491 次 |
最近记录: |