There is a model and a view model:
class model : INotifyPropertyChanged { private int size; public int Size { get { return size; } set { size = value; OnPropertyChanged("Size"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName]string prop = "") { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(prop)); } } class viewmodel : INotifyPropertyChanged { public ObservableCollection<model> Size { get; set; } public viewmodel() { Size = new ObservableCollection<model> { new model { Size=9 } }; } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName]string prop = "") { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(prop)); } } MainWindow.xaml code:
<Window x:Class="mvvm4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Rows="{Binding Path=Size}" Columns="{Binding Path=Size}" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> </Grid> </Window> How do I fill the Uniform grid completely with button elements or others? (Ie, fill the grid with buttons of size size to size?