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
.
精彩评论