一个堆叠面板为每个记录表格内 [英] One stack panel for each record inside table

查看:157
本文介绍了一个堆叠面板为每个记录表格内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关在表中的每个记录(姓名,年龄,市,电子邮件)

我需要有一个堆叠面板 (请参阅下面图像堆栈面板与天蓝色)。

和中添加堆叠面板这样的名单固定面板(见下面的图像码头面板浅灰色颜色)。

怎么可能被实施WPF?

确实用户控制能帮助我吗?

那么,我怎么可以添加的用户控件 DockPanel中 尽可能多的记录congaing表

有没有其他的标准方法

我需要与去 MVVM ,所以考虑这一点给你的答案.....

谢谢......

解决方案

 <窗​​口x:类=WpfApplication7.Window1
的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
标题=窗口1高度=300宽度=300>
  <的ScrollViewer>
< ItemsControl中的ItemsSource ={结合人}>
    < ItemsControl.ItemsPanel>
        < ItemsPanelTemplate>
            < UniformGrid IsItemsHost =真
                         列=2/>
        < / ItemsPanelTemplate>
    < /ItemsControl.ItemsPanel>
    < ItemsControl.ItemTemplate>
        <的DataTemplate>
            < BORDER BorderBrush =黑色保证金=2了borderThickness =2
                    背景=浅蓝色>
                <电网>
                < Grid.RowDefinitions>
                    < RowDefinition>< / RowDefinition>
                    < RowDefinition>< / RowDefinition>
                    < RowDefinition>< / RowDefinition>
                    < RowDefinition>< / RowDefinition>
                < /Grid.RowDefinitions>
                < Grid.ColumnDefinitions>
                    < ColumnDefinition>< / ColumnDefinition>
                    < ColumnDefinition>< / ColumnDefinition>
                < /Grid.ColumnDefinitions>

                < TextBlock的Grid.Row =0文本=名称保证金=5>< / TextBlock的>
                < TextBlock的Grid.Row =1文本=时代保证金=5>< / TextBlock的>
                < TextBlock的Grid.Row =2文本=市保证金=5>< / TextBlock的>
                < TextBlock的Grid.Row =3文本=电子邮件保证金=5>< / TextBlock的>
                    <文本框Grid.Row =0Grid.Column =1文本={结合名}保证金=5>< /文本框>
                    &所述;文本框Grid.Row =1
                             Grid.Column =1
                             文本={结合时代}保证金=5>< /文本框>
                    &所述;文本框Grid.Row =2
                             Grid.Column =1
                             文本={结合城市}保证金=5>< /文本框>
                    <文本框Grid.Row =3
                             Grid.Column =1
                             文本={结合电子邮件}保证金=5>< /文本框>
                < /网格>
                < /边框>
        < / DataTemplate中>
    < /ItemsControl.ItemTemplate>
< / ItemsControl的>
 

在C#code

 公共部分类窗口1:窗口,INotifyPropertyChanged的
{
    公共窗口1()
    {
        人员=新的ObservableCollection<人>();

        的InitializeComponent();
        Persons.Add(新的Person(){名称=约翰福音,年龄= 25,市=新德里,通过电子邮件=abc@abc.com});
        Persons.Add(新的Person(){名称=约翰·2,年龄= 25,市=新德里,通过电子邮件=abc@abc.com});
        Persons.Add(新的Person(){名称=约翰福音3,年龄= 25,市=新德里,通过电子邮件=abc@abc.com});
        Persons.Add(新的Person(){名称=约翰·4,年龄= 25,市=新德里,通过电子邮件=abc@abc.com});
       的DataContext =这一点;
    }

    私人的ObservableCollection<人>人;
    公众的ObservableCollection<人>人{
        得到
        {
            返回的人员;
        }
        组
        {
            人=价值;
            NotifyPropertyChanged(人);
        }
    }

    #地区INotifyPropertyChanged的成员

    公共事件PropertyChangedEventHandler的PropertyChanged;
    私人无效NotifyPropertyChanged(字符串信息)
    {
        如果(的PropertyChanged!= NULL)
        {
            的PropertyChanged(这一点,新PropertyChangedEventArgs(信息));
        }
    }

    #endregion
}
公共类Person
{
    公共字符串名称{;组; }
    公共字符串市{获得;组; }
    公众诠释年龄{获得;组; }
    公共字符串电子邮件{获得;组; }
}
 

更新:新增的ScrollViewer

For each record (Name, Age, City, E-mail) in the table.

I need to have one stack panel (see in image below stack-panel with sky blue color).

And add such list of stack panel in to dock panel (see image below dock-panel with Light Gray color).

How could it be implementing in WPF?

Does user control can help me?

Then how could I add usercontrols inside dockpanel as much records congaing in table?

Is there any other better and standard way?

i needs to going with MVVM, so giving your answer by considering this point.....

Thanks……

解决方案

<Window x:Class="WpfApplication7.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
  <ScrollViewer>
<ItemsControl ItemsSource="{Binding Persons}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid IsItemsHost="True"
                         Columns="2" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Border BorderBrush="Black" Margin="2" BorderThickness="2"
                    Background="LightBlue">
                <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Text="Name" Margin="5"></TextBlock>
                <TextBlock Grid.Row="1" Text="Age" Margin="5"></TextBlock>
                <TextBlock  Grid.Row="2" Text="City" Margin="5"></TextBlock>
                <TextBlock Grid.Row="3" Text="Email" Margin="5"></TextBlock>
                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name}" Margin="5"></TextBox>
                    <TextBox Grid.Row="1"
                             Grid.Column="1"
                             Text="{Binding Age}" Margin="5"></TextBox>
                    <TextBox Grid.Row="2"
                             Grid.Column="1"
                             Text="{Binding City}" Margin="5"></TextBox>
                    <TextBox Grid.Row="3"
                             Grid.Column="1"
                             Text="{Binding Email}" Margin="5"></TextBox>
                </Grid>
                </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

in the c# code

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; }
}

Update : Added Scrollviewer

这篇关于一个堆叠面板为每个记录表格内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆