表格内每条记录的一个堆栈面板
对于表中的每个记录 (姓名,年龄,城市,电子邮件)。
我需要有一个stack panel
(参见下面的stack-panel
,azure色)。
并将这样的stack panel
列表添加到dock panel
(请参见下面的浅灰色 dock-panel
图片)。
怎么可能在WPF中实现?
user control
可以帮助我吗?
然后我怎么能在dockpanel
添加usercontrols 尽可能多的记录congaing在表中 ?
还有其他更好更 标准的方法吗?
我需要使用MVVM ,所以考虑到这一点给出你的答案…..
谢谢……
在c#代码中
public partial class Window1 : Window,INotifyPropertyChanged { public Window1() { Persons = new ObservableCollection(); InitializeComponent(); Persons.Add(new Person() { Name = "John 1", Age = 25, City = "New Delhi", Email = "abc@abc.com" }); Persons.Add(new Person() { Name = "John 2", Age = 25, City = "New Delhi", Email = "abc@abc.com" }); Persons.Add(new Person() { Name = "John 3", Age = 25, City = "New Delhi", Email = "abc@abc.com" }); Persons.Add(new Person() { Name = "John 4 ", Age = 25, City = "New Delhi", Email = "abc@abc.com" }); DataContext = this ; } private ObservableCollection persons; public ObservableCollection Persons { get { return persons; } set { persons = value; NotifyPropertyChanged("Persons"); } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } #endregion } public class Person { public string Name { get; set; } public string City { get; set; } public int Age { get; set; } public string Email { get; set; } }
更新:添加了Scrollviewer
您可以将ItemsControl
与UniformGrid
用作UniformGrid
...
顺便说一句,我不认为StackPanel
是项目模板的最佳选择…通常你会使用Grid
来做这种事情。 当然,您可以创建一个包装此Grid
的UserControl
并在ItemTemplate
使用它