0

In WPF, I am using the MVVM model.

I have a View with a UniformGrid and a ViewModel where I would like to add items to the UniformGrid how would I accomplish this without doing it in the code behind?

1 Answer 1

2

The UniformGrid is a Panel; it's intent is not what you are trying to accomplish. You can achieve what you are trying to do however by adjusting the default ItemsPanelTemplate within an ItemsControl.

        <ItemsControl ItemsSource="{Binding PropertyNameOnViewModel}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>

This will allow you to bind to your ViewModel property within the ItemsControl and the data will get represented visually within a UniformGrid.

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

Comments

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.