I used to get used to WPF/SL. Now I have studied Windows Phone for a while and found that many restrictions have been imposed on Windows Phone sdks. Some methods of WPF/SL have been deleted.
The datatemplate was used in the Windows Phone project today to modify the items style of ListBox. However, during the test, the datatemplate was suddenly found to have no datatype attribute.
As follows:
<phone:PhoneApplicationPage.Resources> <DataTemplate x:Key="listDataTemplate"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding UserID}" /> <TextBlock Text=" Name: "/> <TextBlock Text="{Binding UserName}" /> </StackPanel> </DataTemplate></phone:PhoneApplicationPage.Resources>
You can use <datatemplate X: Key = "listdatatemplate">,
<Datatemplate datatype = "{X: type local: userlist}"> but it cannot be used. It was completely OK in WPF before. Is this removed from Windows Phone?
Check msdn and Baidu. In Windows Phone, The ememplate does not seem to have the datatype attribute, but there is no detailed description, so, Google... (Google was too powerful to be attacked by the wall in tianchao, many webpages could not be opened, and the speed was too slow, so they could not read ...)
Finally, I found some articles in English. For the sake of performance and platform, Windows Phone may remove the datatype attribute. What's more, the trigger in datatemplate is not supported.
I personally think that datatype and trigger are very easy to bind to itemcontrol, and may cause performance loss. But is it really worthwhile to remove such a convenient method for some losses?
Occasionally, it is okay to bind several controls with the key value to the datatemplate, but if it is a large number of controls, this is very cumbersome.
OK. What is the difference between Windows Phone and WPF? Let's look at the code. See no datatype in datatemplate in Windows Phone (2)
<phone:PhoneApplicationPage.Resources> <DataTemplate DataType="{x:Type local:UserList}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding UserID}" /> <TextBlock Text=" Name: "/> <TextBlock Text="{Binding UserName}" /> </StackPanel> </DataTemplate></phone:PhoneApplicationPage.Resources>