110,536
社区成员
发帖
与我相关
我的任务
分享
public class ViewModel1
{
public ObservableCollection<Student> StudentList { get; set; }
public ICommand ClickCommand
{
get
{
return new RelayCommand(o =>
{
StudentList = new ObservableCollection<Student>();
for(int i=0;i<3;i++)
{
Student stu = new Student { Name = "a" };
StudentList.Add(stu);
}
});
}
}
public ViewModel1()
{
}
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new ViewModel1();
}
}
<Grid>
<StackPanel >
<Button Content="Click" Command="{Binding ClickCommand}"></Button>
<ListBox ItemsSource="{Binding StudentList}" DisplayMemberPath="Name"></ListBox>
</StackPanel>
</Grid>
StudentList = new ObservableCollection<Student>();