0

I am implementing a grid that holds a collection of custom user controls. This is a dynamic collection. A good example would be a contact list where each contact is presented by a "card" user control that holds the name, contact info and image of the specific contact.

I'm looking for a sample code that does that using MVVM and WPF, so the item collection will be binded to the ItemsSource of the view. Any ideas?

1
  • I don't know exactly what kind of sample code you are looking for (ready to use vs. tutorial). I will therefore just post this as a comment: drwpf.com/blog/itemscontrol-a-to-z is a resource that helped me very much. It is however very detailed. Commented Feb 11, 2016 at 0:02

1 Answer 1

1

Have you attempted it? Is the "Card" user control a set size (or a size determined by it's contents) or do you need it to scale to the container size (like a wpf grid).

It would be a lot easier letting the control determine it's own size. Shove it in a wrap pannel in an ItemsControl along these lines:

<ItemsControl ItemsSource="{Binding DataItems}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <MyUserControl MyDependencyProperty="{Binding MyDataProperty}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

I doubt you're going to find an example so specific you can just copy and paste it, and we're probably not going to be able to find one for you as there's not really enough information in your question to give a detailed response.

Sign up to request clarification or add additional context in comments.

1 Comment

I actually tried implementing with ListView. ItemsControl looks like a better option for that. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.