Intersoft.Client.UI.Aqua.UXCollection Namespace > UXTreeView Class : IsLoadOnDemand Property |
<CategoryAttribute("Common Properties")> Public Property IsLoadOnDemand As Boolean
Dim instance As UXTreeView Dim value As Boolean instance.IsLoadOnDemand = value value = instance.IsLoadOnDemand
[CategoryAttribute("Common Properties")] public bool IsLoadOnDemand {get; set;}
[CategoryAttribute("Common Properties")] public: property bool IsLoadOnDemand { bool get(); void set ( bool value); }
In addition to the basic features, UXTreeView also offers advanced features such as loading child nodes on demand. This feature is particularly useful to improve the overall performance when the assigned data source is relatively large. To enable load-on-demand, you set the IsLoadOnDemand property of the control to true.
UXTreeView provides two kind of load-on-demand behaviors which you can choose based on your application's scenarios. Each of the load-on-demand behavior is explained in the following sections.
With the Automatic mode, which is the default load-on-demand mode, UXTreeView automatically processes the child items by looking up the requested node in the hierarchy from the given datasource. This mode is ideal when you already have the complete datasource assigned in the ItemsSource and do not require custom implementation of child data retrieval in your application's logic.
For more advanced scenarios, UXTreeView can also completely delegate the child data retrieval process to your application's logic by setting the LoadOnDemandMode property to UseProcessedItem. This mode is ideal for performance-critical data applications where loading all hierarchical data is not feasible due to the data size. In such scenario, you may want to load only several levels of the data initially, then load the rest of the items on demand as they are being expanded.
UXTreeView is specifically designed to elegantly achieve this scenario using MVVM pattern implementation. UXTreeView exposes ExpandedItem property that you can bind in the ViewModel. This allows you to interact with the entity being expanded and write your own logic to retrieve the child items in the ViewModel. Once the child items become available, you assign the original entity to the ProcessedItem property to notify the control that the loading process is completed.
In this mode, a busy indicator will be automatically displayed in each expanded item during the loading progress. You can determine how soon the busy indicator should appear by setting the BusyLatency property to a value in seconds measurement. The default value is 0.1s.
The following code shows how to implement load on demand in UXTreeView with the LoadOnDemandMode property set to UseProcessedItem and IsLoadOnDemand property set to True. The example is implemented using MVVM pattern.
C# |
Copy Code
|
---|---|
public class CompanyEmployee : ModelBase { private String _name; public String Name { get { return this._name; } set { if (this._name != value) { this._name = value; OnPropertyChanged("Name"); } } } } |
C# |
Copy Code
|
---|---|
public class Company : ModelBase { private string _section; private ObservableCollection<CompanyEmployee> _employees; public string Section { get { return this._section; } set { if (this._section != value) { this._section = value; OnPropertyChanged("Section"); } } } public ObservableCollection<CompanyEmployee> Employees { get { return this._employees; } set { if (this._employees != value) { this._employees = value; OnPropertyChanged("Employees"); } } } public Company() { this.Employees = new ObservableCollection<CompanyEmployee>(); } } |
C# |
Copy Code
|
---|---|
public class CompanyViewModel : ViewModelBase { private ObservableCollection<Company> _companies; private object _expandedItem; private object _processedItem; public ObservableCollection<Company> Companies { get { return this._companies; } set { if (this._companies != value) { this._companies = value; OnPropertyChanged("Companies"); } } } public object ExpandedItem { get { return this._expandedItem; } set { if (this._expandedItem != value) { this._expandedItem = value; Company obj = value as Company; ObservableCollection<CompanyEmployee> data = new ObservableCollection<CompanyEmployee>(); //using thread if (obj != null && obj.Employees.Count == 0) { var t = new Thread(() => { try { Thread.Sleep(300); for (int i = 0; i < 20; i++) { data.Add(new CompanyEmployee() { Name = obj.Section + ", Employee " + i.ToString() }); } System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { obj.Employees = data; this.ProcessedItem = value; }); } catch { System.Diagnostics.Debug.WriteLine("Debug"); } }); t.Start(); } else this.ProcessedItem = value; OnPropertyChanged("ExpandedItem"); } } } public object ProcessedItem { get { return this._processedItem; } set { if (this._processedItem != value) { this._processedItem = value; OnPropertyChanged("ProcessedItem"); } } } public CompanyViewModel() { this.LoadData(); } private void LoadData() { this.Companies = new ObservableCollection<Company>(); this.Companies.Add(new Company() { Section = "Human Resource" }); this.Companies.Add(new Company() { Section = "Development and Training" }); this.Companies.Add(new Company() { Section = "Developer" }); this.Companies.Add(new Company() { Section = "Support" }); this.Companies.Add(new Company() { Section = "Project Manager" }); } } |
XAML |
Copy Code
|
---|---|
<Intersoft:UXPage> <Intersoft:UXPage.Resources> <ViewModel:CompanyViewModel x:Key="CompanyViewModel" /> </Intersoft:UXPage.Resources> <Grid x:Name="LayoutRoot"> <Grid.Resources> <Intersoft:HierarchicalDataTemplate x:Key="CompanyEmployeeTemplate" ItemsSource="{Binding Employees}"> <TextBlock Text="{Binding Name}" /> </Intersoft:HierarchicalDataTemplate> <Intersoft:HierarchicalDataTemplate x:Key="CompanyTemplate" ItemTemplate="{StaticResource CompanyEmployeeTemplate}" ItemsSource="{Binding Employees}"> <TextBlock Text="{Binding Section}" /> </Intersoft:HierarchicalDataTemplate> </Grid.Resources> <Intersoft:UXTreeView TreeExpandMode="Multiple" Height="300" IsLoadOnDemand="True" BusyLatency="0.002" LoadOnDemandMode="UseProcessedItem" ExpandedItem="{Binding ExpandedItem, Mode=TwoWay}" ProcessedItem="{Binding ProcessedItem, Mode=TwoWay}" ItemsSource="{Binding Companies}" EnableSlidingAnimation"False" DataContext="{StaticResource CompanyViewModel}" ItemTemplate="{StaticResource CompanyTemplate}"> </Intersoft:UXTreeView> </Grid> </Intersoft:UXPage> |
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2