开发者

Dynamically adding controls to View from Controller

In WPF, I am using the MVVM mo开发者_如何学JAVAdel.

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜