I am trying to set DataTemplates for the items in a XamComboEditor. With the standard ComboBox I just specified a DataTemplate in the Resources with a DataType parameter:
<DataTemplate DataType="{x:Type local:ContactComboTextItem}"> <TextBlock Text="{Binding Text}" Margin="{Binding Margin}"> </TextBlock> </DataTemplate> <DataTemplate DataType="{x:Type local:ContactComboHyperLinkItem}"> <TextBlock Margin="{Binding Margin}" Width="{Binding Width}"> <Hyperlink Click="Hyperlink_Click"> <TextBlock Text="{Binding Path=Text}"/> </Hyperlink> </TextBlock> </DataTemplate> <DataTemplate DataType="{x:Type local:ContactComboGroupHeaderItem}"> <Grid Width="{Binding Width}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="20" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="2" /> </Grid.RowDefinitions> <Image Grid.Row="0" Grid.Column="0" Source="{Binding ImageSource}" Width="16" Height="16" Margin="2,2,2,2"/> <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Text}" FontWeight="Bold" Margin="10,2,2,2" /> <Rectangle Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"> <Rectangle.Fill> <LinearGradientBrush> <GradientStop Color="#FF5397D1" Offset="0.0" /> <GradientStop Color="#FF3EC4E8" Offset="1.0" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> </Grid> </DataTemplate> <DataTemplate x:Key="ContactComboContactItem"> <ContentPresenter Content="{Binding ContactContent}" Margin="{Binding Margin}" /> </DataTemplate>
This does not work with the XamComboEditor. How should I select different DataTemplates based on the type of object in the Items collection?
Thanks,
Glen
Also, How do I paste code in here without cutting if off?
Hello gwinn,
In the control you can set the ItemTemplate property with a key specified. E.g.:
if(XamComboEditor1.ItemsSource is ObservableCollection<Product>){ XamComboEditor1.ItemTemplate = this.Resources["ContactComboHyperLinkItem"] as DataTemplate;}
Also you can find an example in the help docs link: http://help.infragistics.com/NetAdvantage/WPF/2011.2/CLR4.0/?page=DP_xamComboEditor_Working_with_ItemTemplate.html.
When pasting any code in the forum you can surround it with code tags: <code></code>. Just replace the angles with square brackets.
Hello Duane,
that's not the answer to gwinns problem.
The source contains objects of different type that should be rendered using different datatemplates.
I have the same problem.
How do I specify the ItemTemplateSelector in V12.2?
I found a post from 2008 where a user asked for that functionality: http://ko.infragistics.com/community/forums/p/7987/99885.aspx
What happened to that topic?
Best regards,cew3