有没有更快的方法来显示数据网格中的数据? [英] Is there a faster way of how to show data in datagrid?

查看:99
本文介绍了有没有更快的方法来显示数据网格中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在DataGrid中显示数据我使用这种方法:


* .cs

 public class Person 
{
public string name {set;得到; }
public string surname {set;得到; }
public int age {set;得到; }
}

Person p = new Person();
p.name =" John" ;;
p.surname =" Smith" ;;
p.age = 45;
dtgPerson.Items.Add(p);

* .xaml

< DataGrid名称= QUOT; dtgPerson"> 
< DataGrid.Columns>
< DataGridTextColumn Header =" Name" Binding = {Binding Path =" name"} />
< DataGridTextColumn Header =" Surname" Binding = {Binding Path =" surname"} />
< DataGridTextColumn Header =" Age" Binding = {Binding Path =" age"} />
< /DataGrid.Columns>
< / DataGrid>

但我的问题是,如果有更快的方式向数据网格显示数据。 


例如使用MVVM模型。如果MVVM是,它真的更快吗?或者没那么多。


解决方案

嗨    TakeshiKitano,zh


>>但我的问题是,如果有更快的方式向数据网格显示数据。



例如,使用MVVM模型。如果MVVM是,它真的更快吗?或者没那么多。



以下简单示例展示了如何使用MVVM模型,您可以参考它。 / p>

< DataGrid Name =" dtgPerson"的AutoGenerateColumns = QUOT假QUOT; ItemsSource =" {Binding personCollection}" > 
< DataGrid.Columns>
< DataGridTextColumn Header =" Name" Binding =" {Binding Path = name}" />
< DataGridTextColumn Header =" Surname" Binding =" {Binding Path = surname}" />
< DataGridTextColumn Header =" Age" Binding =" {Binding Path = age}" />
< /DataGrid.Columns>
< / DataGrid>


 ///< summary> 
/// DataGridtestsamp.xaml的交互逻辑
///< / summary>
public partial class DataGridtestsamp:Window
{
public DataGridtestsamp()
{
InitializeComponent();
PersonViewModel pv = new PersonViewModel();
this.DataContext = pv;
}
}

公共类PersonViewModel
{
public ObservableCollection< Person> personCollection {set;得到; }

public PersonViewModel()
{
personCollection = new ObservableCollection< Person>();
Person p = new Person();
p.name =" John" ;;
p.surname =" Smith" ;;
p.age = 45;
personCollection.Add(p);
}
}

公共类人员
{
公共字符串名称{set;得到; }
public string surname {set;得到; }
public int age {set;得到; }
}


此外,当我们使用MVVM模式时,并不是因为她有多快,而是因为这种模式适合我们的应用程序。 



MVVM是一种创建客户端应用程序的方法,它利用WPF平台的核心功能,允许对应用程序功能进行简单的单元测试,并帮助开发人员和设计人员一起工作技术难度较小。



没有一种更快的方式向数据网格显示数据,但只有一种合适的显示方式。您需要根据您的项目进行选择。



以下文章供您参考。



WPF中的MVVM
$


WPF中的简单MVVM模式



此外,如果您可以通过将有用的帖子标记为答案来关闭该帖子,将不胜感激。如果您有新问题,可以开始新主题。 
$


最好的问候,



Yong Lu



$




Hi all,

to show data in DataGrid I use this method :

*.cs

public class Person
{
    public string name { set; get; }
    public string surname { set; get; }
    public int age { set; get; }
}

Person p = new Person();
p.name = "John";
p.surname = "Smith";
p.age = 45;
dtgPerson.Items.Add(p);

*.xaml

<DataGrid Name="dtgPerson">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding={Binding Path="name"} />
        <DataGridTextColumn Header="Surname" Binding={Binding Path="surname"} />
        <DataGridTextColumn Header="Age" Binding={Binding Path="age"} />
    </DataGrid.Columns>
</DataGrid>

But my question is if there is a faster way of how to show data to datagrid. 

For example to use MVVM model. And if MVVM yes, is it really faster? or not so much.

解决方案

Hi   TakeshiKitano,

>> But my question is if there is a faster way of how to show data to datagrid. 

For example to use MVVM model. And if MVVM yes, is it really faster? or not so much.

The following simple sample show how to use MVVM model, you can refer it.

<DataGrid Name="dtgPerson" AutoGenerateColumns="False" ItemsSource="{Binding personCollection}" >
            <DataGrid.Columns>
                <DataGridTextColumn  Header="Name"  Binding="{Binding Path=name}"    />
                <DataGridTextColumn Header="Surname" Binding="{Binding Path=surname}" />
                <DataGridTextColumn Header="Age" Binding="{Binding Path=age}" />
            </DataGrid.Columns>
        </DataGrid>

/// <summary>
    /// Interaction logic for DataGridtestsamp.xaml
    /// </summary>
    public partial class DataGridtestsamp : Window
    {
        public DataGridtestsamp()
        {
            InitializeComponent();
            PersonViewModel pv = new PersonViewModel();
            this.DataContext = pv;
        }
    }

    public class PersonViewModel
    {
        public ObservableCollection<Person> personCollection { set; get; }

        public PersonViewModel()
        {
            personCollection = new ObservableCollection<Person>();
            Person p = new Person();
            p.name = "John";
            p.surname = "Smith";
            p.age = 45;
            personCollection.Add(p);
        }
    }

    public class Person
    {
        public string name { set; get; }
        public string surname { set; get; }
        public int age { set; get; }
    }

Besides, when we use the MVVM mode is not because of how fast she is, but because this mode is suitable for our application. 

MVVM is a way of creating client applications that leverages core features of the WPF platform, allows for simple unit testing of application functionality, and helps developers and designers work together with less technical difficulties.

There is no a faster way of to show data to datagrid, but only a suitable way to show. You need to choose according to your project.

The following articles for your reference.

MVVM in WPF

Simple MVVM Pattern in WPF

Besides, It would be appreciated if you could close the thread by marking helpful posts as an answer. If you have a new question you can start a new thread. 

Best Regards,

Yong Lu



这篇关于有没有更快的方法来显示数据网格中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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