简体   繁体   English

Datagrid按需卸载

[英]Datagrid on demand load off

I have a SDK:DATAGRID with 20 columns or so, when it opens up it only shows four fields/columns. 我有一个带有20列左右的SDK:DATAGRID,当它打开时只显示四个字段/列。 Which is what I want and how I designed it 我想要什么以及如何设计

Basically I'm grabbing information based on the user click - EXAMPLE: 基本上,我是根据用户点击来获取信息的-示例:

OWNERNAME.Text = ((TextBlock)EPICGrid.Columns[1].GetCellContent(EPICGrid.SelectedItem)).Text;

and/or 和/或

OWNERNAME2.Text = ((TextBlock)EPICGrid.Columns[16].GetCellContent(EPICGrid.SelectedItem)).Text;

What I'm running into it doesn't grab the information in the cell unless if I scroll and show the column so I can only grab the first 4 columns of data because they show when the grid becomes visible. 除非滚动并显示该列,否则我所遇到的问题不会获取单元格中的信息,因此我只能获取数据的前4列,因为它们显示了何时显示网格。

I can't grab data from columns 5 -20 unless I scoll over and make those columns visible. 我无法从第5列至第-20列中获取数据,除非我将这些列合在一起并使这些列可见。 They don't have to be visible during the click...it just seems like the data doesn't really load until I view the column. 在点击过程中它们不必是可见的……似乎直到我查看该列才真正加载数据。

I guess I should say the first record/row loads all the data/cells/columns and I can grab any data from the first record but the problem happens with records 2 - *. 我想我应该说第一条记录/行会加载所有数据/单元格/列,我可以从第一条记录中获取任何数据,但是问题出在记录2-*上。

Just to clarify - my issue is not a visibility of my columns or rows. 只是要澄清-我的问题不是我的列或行的可见性。 My issue is the SDK DataGrid seems like it is loading the data on demand. 我的问题是SDK DataGrid似乎正在按需加载数据。 So if the column is not in view at one point or another the information in the cell is not available. 因此,如果在某一点或另一点看不到该列,则该单元格中的信息将不可用。

I don't want to show all columns and I don't want to give the user the ability to see all columns so I want to disable the scroll bars but when a user clicks on a certain row I need to grab information in certain cells and since the column is not load yet the information is not there. 我不想显示所有列,也不想赋予用户查看所有列的能力,所以我想禁用滚动条,但是当用户单击某一行时,我需要在某些单元格中获取信息并且由于该列尚未加载,因此信息不存在。

How do I turn the feature load on demand off? 如何关闭按需加载功能?

I did a search and found out that someone had a similar problem with rows loading and the suggestion was setting the VirtualizingStackPanel.VirtualizationMode = Standard 我进行了搜索,发现有人在加载行时遇到了类似的问题,并且建议设置VirtualizingStackPanel.VirtualizationMode = Standard

It almost like the problem is stemmed from VirtualizingStackPanel.VirtualizationMode but I set this property to standard and recycle and no luck. 几乎就像问题出在VirtualizingStackPanel.VirtualizationMode上一样,但我将此属性设置为standard并进行了回收,没有运气。

Here's definition: 定义如下:

By default, a VirtualizingStackPanel creates an item container for each visible item and discards it when it is no longer needed (such as when the item is scrolled out of view). 默认情况下,VirtualizingStackPanel为每个可见项目创建一个项目容器,并在不再需要它时(例如,当项目滚动到视图外时)将其丢弃。 When an ItemsControl contains a lot of items, the process of creating and discarding item containers can negatively affect performance. 当ItemsControl包含很多项目时,创建和丢弃项目容器的过程可能会对性能产生负面影响。 When VirtualizingStackPanel.VirtualizationMode is set to Recycling, the VirtualizingStackPanel reuses item containers instead of creating a new one each time. 当VirtualizingStackPanel.VirtualizationMode设置为Recycling时,VirtualizingStackPanel会重用项目容器,而不是每次都创建一个新容器。

On initial load, if the cell is not visible I can not grab the cells content (unless it is the first record/row). 初始加载时,如果看不到该单元格,则无法获取该单元格的内容(除非它是第一个记录/行)。 Once and after the cell / column is visible then the information is available. 在单元格/列可见之后,该信息可用。

I think you are expected to deal with the data that the row is bound to directly and not pull the data out of the controls. 我认为您应该直接处理该行绑定到的数据,而不要将数据从控件中拉出。 This makes sense since it is two way data binding so the data is updated as you are changing it (assuming it implements the INotifyPropertyChanged Interface). 这是有道理的,因为它是两种方式的数据绑定,所以在您更改数据时会更新数据(假设它实现了INotifyPropertyChanged接口)。

An example would be where a datagrid is bound to a collection of type MyEntity. 一个示例是将数据网格绑定到类型MyEntity的集合。

     private void DataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.DataGrid1.SelectedItem == null)
                return;

            MyEntity myEntity = (MyEntity)this.DataGrid1.SelectedItem;

            // at this point you have the (updated) data the row is bound to.
           MessageBox.Show("You Selected: " + myEntity.name);
           ...

Another example is where there is a button on each row. 另一个示例是每行上都有一个按钮。 The code to process when a button is clicked looks something like: 单击按钮时要处理的代码如下所示:

      private void btnProcessEntity_Click(object sender, RoutedEventArgs e)
      {

         Button btn = sender as Button;
         MyEntity myEntity = btn.DataContext as MyEntity;

          // clicking a button in a row doesn't select the row, so select it.
         this.DataGrid1.SelectedItem = myEntity;  
         MessageBox.Show("Will Process: " + myEntity.name);

          ...
       }

If you are not familiar with some of the technologies that normally are used with Silverlight check out these Video Tutorials . 如果您不熟悉Silverlight通常使用的某些技术,请查看这些视频教程 It is VB.Net, but the code is really not the focus - it is focused on a Silverlight application architecture. 它是VB.Net,但是代码实际上并不是重点-它专注于Silverlight应用程序体系结构。 I would start with "Intro to SL4 and WCF Ria Services" and then view one of the ones on MVVM. 我将从“ SL4和WCF Ria服务简介”开始,然后在MVVM上查看其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM