Here is my template I'm using in my projects:
Data Template
<telerik:GridViewDataColumn Width="150" DataMemberBinding="{Binding Path=StackOptimizerSelectedRule}"
Header="Rules"
IsFilterable="False" IsReorderable="False">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate DataType="flowConfiguration:StackOptimizerParameterRuleTreeViewModel">
<TextBlock Text="{Binding StackOptimizerSelectedRule, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource EnumTypeConverterKey}}"></TextBlock>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate DataType="flowConfiguration:StackOptimizerParameterRuleTreeViewModel">
<ComboBox
ItemsSource="{Binding Source={StaticResource StackOptimizerSelectionRules}}"
SelectedItem="{Binding StackOptimizerSelectedRule, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="flowConfiguration:StackOptimizerParameterRuleTreeViewModel">
<TextBlock Text="{Binding Converter={StaticResource EnumTypeConverterKey}, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
Explanations
Here are two templates. The GridViewDataColumn.CellTemplate
will be available when containing cell is not in a focus. The CellEditTemplate
will be available when a containing cell is in a focus and user change his selection.
Please keep in your mind next things, you have several ways to bound the ItemsSource of the combo:
- Regular binding
ItemsSource="{Binding SourceCollection, UpdateSourceTrigger=PropertyChanged}"
. Use this way when your SourceCollection is presenting in the Cell DataContext.
- Relative binding
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type PutHereTheTypeOfActualParentThatHoldsDataContextYouNeed}}, Path=DataContext.SourceCollection}"
. Use this way when your SourceCollection is inside the Parent's data context.
- Source from xaml
ItemsSource="{Binding Source={StaticResource SourceCollection}}"
. Use this way when your SourceCollection is static collection Generated in Xaml(for example; based on enum types). You need the next declaration in your <SomeParentVisualAccessibleByridViewDataColumn.Resource>
section.
Declaration of source for the third (in addition read the next article)
<ObjectDataProvider x:Key="SourceCollection"
MethodName="GetValues"
ObjectType="{x:Type flowConfiguration:StackOptimizerSelectionRules}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="flowConfiguration:StackOptimizerSelectionRules"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
In my opinion your problem is an incorrect combo's ItemsSource biding, check if you have related binding error exception in your output window. Let me know if you need any help.
Regards.