0

I've try to adopt the CollectionView of iOS on WPF. The background is the migration of an iOS App to a Windows Store App (Windows 10 Universal App).

I try to create a List of clickable objects which contain:

  • a label
  • a image

How can I do this? It should look like this:

CollectionView on iOS

https://i.stack.imgur.com/ETsqy.png

Can somebody give me an example of XAML code for my purpose?

Maximus1809
  • 575
  • 1
  • 10
  • 30
  • That's what *data templates* are in wpf for. Google for that (book is of course a better option), [here](http://stackoverflow.com/q/22688068/1997232) is a starting point. – Sinatr Jul 06 '15 at 08:08

1 Answers1

3

Sure. Google for itemscontrol, there you get in "ItemsSource" a specific type of model (Class), and that class type is your itemscontrol dataContext. in this control you can handle ItemTemplate in order to create a template to the given class.

 <ItemsControl Name="icTodoList" ItemsSource="{Binding MyClass}">
                    <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                    <StackPanel>
                    <Image Source="{Binding Image)"
                    <TextBlock Text="{Binding Title}"
                                    </StackPanel>
                            </DataTemplate>
                    </ItemsControl.ItemTemplate>
            </ItemsControl>
Ben Cohen
  • 1,380
  • 1
  • 9
  • 12
  • 1
    Or better use a ListBox to make items selectable ("clickable"). – Clemens Jul 06 '15 at 07:37
  • Now it's edited. Ofcourse you need to change the MyClass to your collection binding, and the Image and Title properties to your class's properties, if it wasn't obvious – Ben Cohen Jul 06 '15 at 08:42