- 浏览: 399596 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
Followed by the copy of the blog on http://bea.stollnitz.com/blog/?p=338 (with title of UI Virtualization), Joe has created his own blog with some connotation.
The article from the original post does not include the code, in this blog, I have implemented some code which can demonstrate the use of the technique that has been inroduced.
In summary, the following technique has been inroduced
- VirtualizingStackPanel to ItemsPaneTemplate
- Container Recycling
- Deferred Scrolling
- UI Virtualizing extended to Hierarchical Data structure, such as the TreeView
Below shows the Xaml definition and the code behind source code (in C#)
The xaml code
<Window x:Class="Virtualization.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Virtualization" Title="MainWindow" Height="650" Width="700" > <!-- this template is copying from the twiki of http://vbcity.com/blogs/xtab/archive/2009/11/25/wpf-how-to-list-select-and-apply-fonts.aspx with the title of WPF: How To List, Select and Apply Fonts --> <Window.Resources> <DataTemplate x:Key="FontDisplay"> <TextBlock Text="{Binding}" FontFamily="{Binding}" FontSize="14" /> </DataTemplate> </Window.Resources> <StackPanel> <!-- the ComboBox that has no data virtualization --> <ComboBox x:Name="CombFonts" ItemsSource="{Binding}" Margin="4,22,9,27" ItemTemplate="{StaticResource FontDisplay}" > </ComboBox> <Separator /> <TextBlock Margin="6,10, 0, 1" Text="Combo with VirualizingStackPanel as ComboBox.ItemsPanel" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" /> <!-- --> <ComboBox x:Name="CombFonts2" ItemsSource="{Binding}" Margin="4,22,9,27" ItemTemplate="{StaticResource FontDisplay}" > <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox> <Separator /> <TextBlock Margin="6,10, 0, 1" Text="ListBox with Container recyling" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" /> <!-- the following demonstrate the use of the VirtualizingMode in VirtualizingStackPanel The comment is based on the article http://bea.stollnitz.com/blog/?p=338 section Container recycling the principle/foundation of the Container recycle is as follow. 30 ListBoxItems are created to display the visible data. When the user scrolls the ListBox, instead of discarding ListBoxItems that scroll out of view and creating new ones for the data items that scroll into view, WPF reuses the existing ListBoxItems, So basically it is the ListBoxItems reuse. There are two values of the VirtualizationMode, they are * Recyling * Standard To maintain the backword compatibility with the behavior of the earlier versions, container recycling is disable by default (the default VirtualizationMode is "Standard") --> <ListBox VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding}" ItemTemplate="{StaticResource FontDisplay}" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Auto" Height="100" > </ListBox> <Separator /> <TextBlock Margin="6,10, 0, 1" Text="ListBox with Defered Scrolling" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" /> <!-- “Deferred scrolling” is a feature that allows the user to drag the scroll bar thumb around without changing the displayed items until the scroll bar thumb is released. --> <ListBox ScrollViewer.IsDeferredScrollingEnabled="True" ItemsSource="{Binding}" ItemTemplate="{StaticResource FontDisplay}" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Auto" Height="100" /> <Separator /> <TextBlock Margin="6,10, 0, 1" Text="Hierarchical Data with IsVirtualizing=True" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" /> <!-- Since the advent of .NET framework 3.5, the team has added the Virutalization Support to the Hierarchical structure, such as the TreeView So use the virtualization, you can need to do is to set the following tags VirtualizingStackPanel.IsVirtualizing="True" But if you want to have more control on the Data virtualization, I would suggest you take a look at the example of TreeView3 --> <TreeView ItemsSource="{Binding Path=RootKeys}" VirtualizingStackPanel.IsVirtualizing="True" x:Name="TreeViewRegistry" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Auto" Height="100" > <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type local:RegistryKeyHolder1}" ItemsSource="{Binding Path=SubKeys}"> <TextBlock Text="{Binding Path=ShortName}" /> </HierarchicalDataTemplate> </TreeView.Resources> </TreeView> </StackPanel> </Window>
The C# code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Security.Permissions; using System.Security; using System.Collections.ObjectModel; using Microsoft.Win32; namespace Virtualization { [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, Read = "HKEY_CURRENT_CONFIG")] [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, Read = "HKEY_CURRENT_USER")] /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); InitializeDataContextToSystemFonts(); InitializeTreeViewDataSourceToRegistries(); } private void InitializeDataContextToSystemFonts() { this.DataContext = Fonts.SystemFontFamilies; } private void InitializeTreeViewDataSourceToRegistries() { this.TreeViewRegistry.DataContext = new RegistryData1(); } } #region TreeView Data // this TreeView data is copied from the previous example on the TreeViews. // since we want to make the TreeView simple, so we take the example from // TreeView1. which does not have UI Virtualization and no DataVirtualization // #region Data - No UI visualization, no data virtualization public class RegistryData1 { private ObservableCollection<RegistryKeyHolder1> rootKeys; private int dataItemsCount; /// <summary> /// The root keys, such as HKEY_CURRENT_CONFIG, or HKEY_CURRENT_USER /// </summary> public ObservableCollection<RegistryKeyHolder1> RootKeys { get { return rootKeys; } } /// <summary> /// Total number of items that has been populated /// </summary> public int DataItemsCount { get { return dataItemsCount; } } public RegistryData1() { this.rootKeys = new ObservableCollection<RegistryKeyHolder1>(); rootKeys.Add(new RegistryKeyHolder1(Registry.CurrentUser)); rootKeys.Add(new RegistryKeyHolder1(Registry.CurrentConfig)); this.dataItemsCount = 2; PopulateSubKeys(this.rootKeys); } private void PopulateSubKeys(ObservableCollection<RegistryKeyHolder1> keys) { foreach (RegistryKeyHolder1 keyHolder in keys) { // expand each of the subkeys keyHolder.PopulateSubKeys(); this.dataItemsCount += keyHolder.SubKeys.Count; // set a hard limit so that we don't blow if (this.dataItemsCount >= 5000) { return; } PopulateSubKeys(keyHolder.SubKeys); } } } /// <summary> /// Registry Key Holder /// </summary> public class RegistryKeyHolder1 { private RegistryKey key; private ObservableCollection<RegistryKeyHolder1> subKeys; public RegistryKey Key { get { return key; } } public string ShortName { get { return key.Name.Substring(key.Name.LastIndexOf('\\') + 1); } } public ObservableCollection<RegistryKeyHolder1> SubKeys { get { return subKeys; } } public RegistryKeyHolder1(RegistryKey key) { this.key = key; this.subKeys = new ObservableCollection<RegistryKeyHolder1>(); } /// <summary> /// Populate <paramref name="this"/> SubKeys collection /// </summary> /// <remarks> /// Lazy populate the subkeys </remarks> public void PopulateSubKeys() { try { string[] subKeyNames = this.key.GetSubKeyNames(); for (int i = 0; i < subKeyNames.Length; ++i) { this.subKeys.Add(new RegistryKeyHolder1(this.key.OpenSubKey(subKeyNames[i]))); } } catch (SecurityException ex) { System.Console.WriteLine(ex.Message); } } } #endregion Data - No UI visualization, no data virtualization #endregion TreeView Data }
and below shows the snapshot of the application in action.
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1976first let’s see an example ... -
WPF – Virtualization – VirutalizationStackPanel and ItemsPanelTemplate
2013-08-05 21:55 1410Topic: WPF – Virtualization – ... -
wpf - BehaviorBase and one use examples
2013-06-18 18:41 1311Behavior is something that we ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1918You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5330As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1185Recently I was trying to debug ... -
wpf - default implicit style
2013-05-10 10:24 794We know that if you left out ... -
wpf - Style setter on the attached property
2013-05-08 14:54 2851I believe that you are familia ... -
wpf - specify enum values in xaml
2013-05-08 11:31 3585Many a situation you find tha ... -
wpf - IG xamDataGrid bind to XmlDataProvider with Xml Island
2012-12-18 14:28 1285Sometimes you may bind to some ... -
wpf - translate winform button/mouse event to wpf events
2012-12-12 17:37 2162It is common that we sometimes ... -
wpf - Freezable and its meaning
2012-09-27 12:38 0This article is based on the di ... -
wpf - Customize the grid lines for original wpf Grid control
2012-09-27 12:01 1458The System.WIndows.Controls.Gri ... -
c# - Convert from System.Drawing.Image to System.WIndows.Media.ImageSource
2012-09-25 14:27 7417In Previous discussion, we have ... -
wpf - Get Effective DependencyProperty value on a DependencyObject
2012-08-28 19:05 1044As discussed in my previous pos ... -
wpf - Default(Theme) style and its DefaultStyleKey
2012-08-28 17:54 1387As dicsused in the subsection o ... -
wpf - Dependency Property Value Precedence
2012-08-28 18:56 882A dependency property to an Dep ... -
wpf - WPF TemplateBinding vs RelativeSource TemplatedParent
2012-08-28 14:20 3713This is a post that summarizes ... -
wpf - ICutomTypeDescriptor , PropertyDescriptor and its use in PropertyGrid
2012-08-28 14:04 3580The type ICustomTypeDe ... -
wpf - tips to convert UI controls in WPF/Silverlight/Winforms into a Bitmap
2012-08-27 17:44 975In previous discussion, we have ...
相关推荐
Eliminates the need to deal with the different available Fingerprint APIs, including Imprint and Samsung Pass. Fixes undocumented bugs and idiosyncrasies in the underlying APIs. Supports more Imprint ...
Processing of signals is often facilitated by transforming to a representation in which individual components are statistically independent. In such a natural coordinate system, the components of the ...
最新版,2013版,英文原版,Highly readable paperback reprint of one of the great time-tested classics in the field of signal processing Together with the reprint of Part III and the new Part IV,...
reprint 是一个适用于 Python 2/3 的简易变量绑定与多行输出刷新的库
I am pleased that Springer-Verlag has decided to reprint this book, givingme the opportunity to include a number of corrections. The changes in this printing are mainly limited to the correction of...
本资源"reprint-0.3.0.tar.gz"就是从PyPI官网获取的一个Python库——`reprint`的特定版本,版本号为0.3.0。 `reprint`库主要解决的是在Python程序中动态更新控制台输出的问题。在开发过程中,我们有时需要实时显示...
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been ...
Gartner在2018年发布的研究笔记中,特别提到了应用安全测试(AST)市场的现状和发展趋势。研究笔记的标题为“应用安全测试市场的魔法象限”,它由分析师Ayal Tirosh、Dionisio Zumerle和Mark Horvath撰写,涉及...
reprint 使用说明 直接从datasource,dbgrid,stringgrid导入数据, 只需简单设置,不用手工制作,即可生成您需要的报表,具有预览功能。即可自定义纸张,又可适应 打印机默认纸张。各种打印设置,功能更强大。 ...
Introduction to Finite and Spectral Element Methods Using MATLAB®Second ... If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been ...
- 本书的再版信息(Softcover reprint of the hardcover 2nd edition 2004)表明,该书不仅一次印刷,而且对之前的版本进行了更新和再版,说明其内容具有一定的时效性和持续的学术价值。 - 书的封面设计、排版印刷...
reprint 使用说明 本人长期使用delphi做数据库的开发,报表控件使用Quickrpt,在打印上经常遇到一些问题,于是自己经常编写一部分打印的程序,经过总结开发了这个控件。 本控件可打印 datasource,dbgrid,...
reprint是一个Python 2/3模块,用于绑定变量并刷新终端中的多行输出。 用于计算Unicode字符宽度的解决方案来自 特征 Python 2/3支持 简单的变量绑定和变量更改后自动刷新命令行 同时多行刷新,每行绑定到不同的...