C# 表中的每条记录都有一个堆栈面板
对于表中的每个记录名称、年龄、城市、电子邮件 我需要有一个堆栈面板看到下面的堆栈面板与天蓝色的图像 并将这样的堆栈面板列表添加到dock panel中,请参见dock panel下面的浅灰色图像 它是如何在WPF中实现的 用户控制可以帮助我吗 那个么,我怎样才能在dockpanel中添加用户控件,使表中包含的记录数量相同呢 还有其他更好、更标准的方法吗 我需要使用MVVM,所以请考虑这一点,给出您的答案 谢谢……您可以使用带有UniformGrid的ItemsControl作为ItemsPanel 顺便说一句,我不认为StackPanel是项目模板的最佳选择。。。通常,您会使用网格来处理这类事情。当然,您可以创建一个包装此网格的UserControl,并在ItemTemplate中使用它。您可以使用一个ItemsControl,将UniformGrid用作ItemsPanel 顺便说一句,我不认为StackPanel是项目模板的最佳选择。。。通常,您会使用网格来处理这类事情。当然,您可以创建一个用户控件来包装这个网格,并在ItemTemplate中使用它 在c代码中C# 表中的每条记录都有一个堆栈面板,c#,.net,wpf,mvvm,C#,.net,Wpf,Mvvm,对于表中的每个记录名称、年龄、城市、电子邮件 我需要有一个堆栈面板看到下面的堆栈面板与天蓝色的图像 并将这样的堆栈面板列表添加到dock panel中,请参见dock panel下面的浅灰色图像 它是如何在WPF中实现的 用户控制可以帮助我吗 那个么,我怎样才能在dockpanel中添加用户控件,使表中包含的记录数量相同呢 还有其他更好、更标准的方法吗 我需要使用MVVM,所以请考虑这一点,给出您的答案 谢谢……您可以使用带有UniformGrid的ItemsControl作为ItemsPan
public partial class Window1 : Window,INotifyPropertyChanged
{
public Window1()
{
Persons = new ObservableCollection<Person>();
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<Person> persons;
public ObservableCollection<Person> 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
在c代码中
public partial class Window1 : Window,INotifyPropertyChanged
{
public Window1()
{
Persons = new ObservableCollection<Person>();
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<Person> persons;
public ObservableCollection<Person> 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@Pritesh:顺便说一句,这不是MVVM。此外,窗口已经是DependencyObject,因此使用INotifyPropertyChanged是浪费时间。只需使用DependencyProperties和roll。@will,是的,但我可以使用上述.xaml代码创建viewusercontrol,也可以使用上述所需代码创建ViewModel和Model……它将是MVVM…………Kumar,如果项目数量增加,是否可以添加滚动条。?????因此,我们可以访问屏幕上显示的每个数据网格………@Pritesh:顺便说一句,这不是MVVM。此外,窗口已经是DependencyObject,因此使用INotifyPropertyChanged是浪费时间。只需使用DependencyProperties和roll。@will,是的,但我可以使用上述.xaml代码创建viewusercontrol,也可以使用上述所需代码创建ViewModel和Model……它将是MVVM…………Kumar,如果项目数量增加,是否可以添加滚动条。?????因此,我们可以访问屏幕上显示的每个数据网格。。。。。。。。。。
public partial class Window1 : Window,INotifyPropertyChanged
{
public Window1()
{
Persons = new ObservableCollection<Person>();
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<Person> persons;
public ObservableCollection<Person> 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; }
}