Hi,
I need a combobox in a xamdatagrid with two columns.
it's possibile to apply a template style to a ComboBoxItemsProvider to do this?
Thks for help.
Sacha
Hello,
I am not sure if this approach is the best one for this scenario. The XamComboEditor uses a ComboBox when in edit mode and a text element when not in edit mode. If you want to have a XamComboEditor with multiple columns, you can create a style for the ComboBox and assign that style to the ComboBoxStyle property of the XamComboEditor.
<igEditors:XamComboEditor.ComboBoxStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=FirstName}" />
<TextBlock Text="{Binding Path=LastName}" Margin="2,0,0,0"/>
<TextBlock Text="{Binding Path=Age}" Margin="2,0,0,0"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</igEditors:XamComboEditor.ComboBoxStyle>
This should take care when not in edit mode. Here, you can set the DisplayMemberPath property (of the ComboBoxItemsProvider) to only one of the properties of the underlying class. If you want multiple columns when not in edit mode, there are couple of ways to achieve this:
1. Use IValueConverter for the ValueToTextConverter property
2. Override the ToString() method of the underlying class.
These two are show in the attached sample.
When a ComboBoxItem is selected it display the three columns correctly.But the problem is when I want to select a ComboBoxItem. The list of items appears as normaly with one column.
How can I solve the problem?
This is the style that I use:
<Style x:Key="CorsoLaureaFieldStyle" TargetType="{x:Type Editors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource CorsoLaureaItemsProvider}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Editors:XamComboEditor}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.333*"/> <ColumnDefinition Width="0.333*" /> <ColumnDefinition Width="0.333*" /> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Path=DataItem.corsolaurea.corsolaurea.acronimo}"/> <TextBlock Grid.Column="1" Text="{Binding Path=DataItem.corsolaurea.annoaccademico.annoAccademico}"/> <TextBlock Grid.Column="2" Text="{Binding Path=DataItem.corsolaurea.dipartimento.dipartimento}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
Yes...
I apply the style to the XamComboEditor and the "problem" was solved.
Thks...
Hello Sacha,
I am not sure why you want to style the ComboBoxItemsProvider. That would not be helpful. You probably want to create a style for the XamComboEditor and apply it at the EditorStyle property of the field's settings.