Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2320
XamComboEditor, DataTemplate & ItemsProvider
posted

How can I set the DataTemplate on the XamComboEditor when its items are coming from a ComboBoxItemsProvider?

 

The items in the ComboBoxItemsProvider are objects with various properties. Say it contains ID and Name. How do I get the XamComboBox to display the ID and Name properties as one item? Eg. Instead of displaying names: "smith, brown, black", display IDs and names: "1 smith, 2 brown, 3 black"?

 

I'm aware that you can set the data template through ComboBoxStyle property but I'm having trouble with the binding. 

 

 

<igEditors:XamComboEditor Name="cbo" ItemsProvider="{StaticResource cbip}">

    <igEditors:XamComboEditor.ComboBoxStyle>

        <Style TargetType="ComboBox">

            <Setter Property="ItemTemplate">

                <Setter.Value>

                    <DataTemplate>

                        <StackPanel>

                            <TextBlock Text="{Binding Path=ID,

                            RelativeSource={RelativeSource FindAncestor,

                            AncestorType=igEditors:XamComboEditor}}"/>

                            <TextBlock Text="{Binding Path=Name,

                            RelativeSource={RelativeSource FindAncestor, 

                            AncestorType=igEditors:XamComboEditor}}"/>

                        </StackPanel>

                    </DataTemplate>

                </Setter.Value>

            </Setter>

        </Style>

    </igEditors:XamComboEditor.ComboBoxStyle>

</igEditors:XamComboEditor>

 

Parents
  • 54937
    Offline posted

    Since you want to show the Id & Name of your object (i.e. the DataContext), you should remove the RelativeSource otherwise you are trying to bind to properties named Id & Name on the XamComboEditor. If you still have an issue please post a small project showing the problem.

Reply Children