1
votes

I need to create an ordering list having as elements strings and images (some items are text, other -images). I have to configure this list from code behind, not in xaml. I created a class :

public class SimpleChoicePair
{
    public SimpleChoice Choice { get; set; }
    public FrameworkElement Content { get; set; }
}

where as Content I have TextBlock or Image objects. My listbox looks like:

var listboxChoices = new ListBox();

var list = new ObservableCollection();

listboxChoices.DisplayMemberPath = "Content";

listboxChoices.ItemsSource = choicesList;

But the items in the list display only the class name of TextBlock or Image. How can I display the uiElements themselves? Thanks for any help

1

1 Answers

0
votes

If i am right you are looking about the itemtemplateselector on the basis of your content for e.g if content type text then show the textbock or if its image type then show me the images. see below exampbles.

http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemtemplateselector.aspx

http://www.switchonthecode.com/tutorials/wpf-tutorial-how-to-use-a-datatemplateselector