We are writing a very specialized ItemsControl , which actually has three ContentPresenter per 'lines, each of which is tied to a different object (I think, a poor personβs network) instead of a more general one, such as a ListBox .
Now that the ListBox , unless you explicitly specify either an ItemTemplate or an ItemTemplateSelector , there seems to be an internal selector that applies a template based solely on the data type. However, our ContentPresenter do not collect them. We also tried switching them to ContentControl , but that didn't work either.
Now I know that I can just write my own DataTypeTemplateSelector that does this, but I wonder if this function has already been βbakedβ somewhere, it was thought that it is used with many ItemsControl ( ListBox , TreeView , ComboBox ', DataGrid , etc.) .d.) and in accordance with this MSDN article ...
http://msdn.microsoft.com/en-us/library/ms742521.aspx
... it should work by default! But then again, this is not so.
Here is our (pseudo) code ...
<UserControl.Resources> <DataTemplate DataType="local:SomeTypeA"> <TextBlock Text="{Binding Converter={c:DataTypeNameConverter}}" Foreground="Blue" /> </DataTemplate> <DataTemplate DataType="local::SomeTypeB"> <TextBlock Text="{Binding Converter={c:DataTypeNameConverter}}" Foreground="Purple" /> </DataTemplate> <DataTemplate DataType="local::SomeTypeC"> <TextBlock Text="{Binding Converter={c:DataTypeNameConverter}}" Foreground="Purple" /> </DataTemplate> </UserControl.Resources> <ContentControl Content="{Binding Field1}" /> <ContentPresenter Content="{Binding Field2}" /> <ListBox ItemsSource="{Binding AllItems}"
So ... someone wants to take a hit, why not?
wpf datatemplate contentpresenter contentcontrol
MarqueIV
source share