Skip to content

Commit fb0a8f6

Browse files
committed
docs: add DataGrid appendix to readme
1 parent d68c78e commit fb0a8f6

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

DataVirtualizationDemo/Window1.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
dz:VirtualListLoadingIndicator.IsAttached="True"
9393
Height="200">
9494
<DataGrid.Columns>
95-
<DataGridTextColumn Width="60" Binding="{Binding Data.Id}" Header="Id" SortMemberPath="Id" />
95+
<DataGridTextColumn Width="60" Binding="{Binding Data.Id}" Header="Id" SortMemberPath="Id" />
9696
<DataGridTextColumn Width="120" Binding="{Binding Data.FirstName}" Header="First Name" SortMemberPath="FirstName" />
9797
<DataGridTextColumn Width="120" Binding="{Binding Data.LastName}" Header="Last Name" SortMemberPath="LastName" />
9898
<DataGridTemplateColumn Width="100" Header="DataTemplate test">

README.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DevZest.DataVirtualization
22

3-
[The DevZest Blog | WPF Data Virtualization](http://web.archive.org/web/20180814144210/http://www.devzest.com:80/blog/post/WPF-Data-Virtualization.aspx)
3+
> The original post can be accessed from Internet Archive: [The DevZest Blog | WPF Data Virtualization](http://web.archive.org/web/20180814144210/http://www.devzest.com:80/blog/post/WPF-Data-Virtualization.aspx)
44
55
![DataVirtualization](images/DataVirtualization.jpg)
66

@@ -18,9 +18,9 @@ The attached source code contains a highly reusable component which resolves all
1818

1919
First of all, your UI should only demand data items actually visible on screen. As of .NET 3.5 SP1, this is what you can do for `ItemsControl` and derivatives:
2020

21-
- Make the number of UI elements to be created proportional to what is visible on screen using`VirtualizingStackPanel.IsVirtualizing="True"`.
22-
- Have the framework recycle item containers instead of (re)creating them each time, by setting`VirtualizingStackPanel.VirtualizationMode="Recycling"`.
23-
- Defer scrolling while the scrollbar is in action by using `ScrollViewer.IsDeferredScrollingEnabled="True"`. This improves *perceived* performance, by waiting until the user releases the scrollbar thumb to update the content.
21+
- Make the number of UI elements to be created proportional to what is visible on screen using [`VirtualizingStackPanel.IsVirtualizing="True"`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.virtualizingstackpanel.isvirtualizing?view=netframework-4.0).
22+
- Have the framework recycle item containers instead of (re)creating them each time, by setting [`VirtualizingStackPanel.VirtualizationMode="Recycling"`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.virtualizationmode?view=netframework-4.8).
23+
- Defer scrolling while the scrollbar is in action by using [`ScrollViewer.IsDeferredScrollingEnabled="True"`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.scrollviewer.isdeferredscrollingenabled?view=netframework-4.8). This improves *perceived* performance, by waiting until the user releases the scrollbar thumb to update the content.
2424

2525
For more information, please read [this post](http://web.archive.org/web/20180814144210/http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/98090161-0abf-4799-bbcb-852dcc0f0608).
2626

@@ -341,6 +341,34 @@ A simple WPF window with a `ListView` was created to allow the user to experimen
341341

342342
That's all! Hope you will enjoy using this component.
343343

344+
## Appendix: DataGrid
345+
346+
`VirtualList<T>` can also be applied to `DataGrid`:
347+
348+
```xaml
349+
<DataGrid
350+
x:Name="dataGrid"
351+
EnableRowVirtualization="True"
352+
ScrollViewer.IsDeferredScrollingEnabled="True"
353+
dz:VirtualListLoadingIndicator.IsAttached="True"
354+
Height="200">
355+
<DataGrid.Columns>
356+
<DataGridTextColumn Width="60" Binding="{Binding Data.Id}" Header="Id" SortMemberPath="Id" />
357+
<DataGridTextColumn Width="120" Binding="{Binding Data.FirstName}" Header="First Name" SortMemberPath="FirstName" />
358+
<DataGridTextColumn Width="120" Binding="{Binding Data.LastName}" Header="Last Name" SortMemberPath="LastName" />
359+
<DataGridTemplateColumn Width="100" Header="DataTemplate test">
360+
<DataGridTemplateColumn.CellTemplate>
361+
<DataTemplate>
362+
<ContentControl Content="{Binding Data}" />
363+
</DataTemplate>
364+
</DataGridTemplateColumn.CellTemplate>
365+
</DataGridTemplateColumn>
366+
</DataGrid.Columns>
367+
</DataGrid>
368+
```
369+
370+
However, [`DataGridRow`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.datagridrow?view=netframework-4.8) is not a `ContentControl`. `AutoLoad` needs to depend on `FrameworkElement.DataContextProperty` (or `DataGridRow.Item`) instead of `ContentControl.ContentProperty` to work.
371+
344372
## License
345373

346374
This component and the demo application, is under MIT license:
@@ -351,4 +379,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
351379

352380
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
353381

354-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
382+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
383+
384+
## See Also
385+
- [How to sort data virtualized items in WPF](https://github.com/bstollnitz/old-wpf-blog/tree/master/64-DataVirtualizationFilteringSorting)

0 commit comments

Comments
 (0)