1.axaml中引用命名空间
xmlns:model="using:IDataTemplateSample.Models"
2.Grid支持行列的简化写法
<Grid RowDefinitions="Auto, Auto, *" ColumnDefinitions="Auto, *"/>
3.DataTemplate 根据DataType自动选择对应类型的样式,使用Window.DataTemplates加载多个DataTemplate自动选择显示不同样式,类似WPF的DataTemplateSelector选择器
<Window.DataTemplates> <!-- Add a DataTemplate for a Student --> <!-- Mind the order of the Templates. Begin with the most specific first. --> <DataTemplate DataType="model:Student"> <StackPanel> <TextBlock FontWeight="Bold" Text="{Binding Grade, StringFormat='I am a student in {0}. grade'}" /> <!-- We re-use the PersonTemplate here by using DynamicResource --> <ContentControl Content="{Binding}" ContentTemplate="{DynamicResource My.DataTemplates.Person}" /> </StackPanel> </DataTemplate> <!-- Add a DataTemplate for a Teacher --> <DataTemplate DataType="model:Teacher"> <StackPanel> <TextBlock FontWeight="Bold" Text="{Binding Subject, StringFormat='I am a teacher for: "{0}"'}" /> <!-- We use a UserControl here to display the data --> <view:PersonView /> </StackPanel> </DataTemplate> </Window.DataTemplates>
4.
标签:样式,笔记,WPF,不同点,DataTemplate,Avalonia From: https://www.cnblogs.com/mqxs/p/17900160.html