Esempio n. 1
0
        /// <summary>
        /// Execute method is called when any item is requested for load-on-demand items.
        /// </summary>
        /// <param name="obj">TreeViewNode is passed as default parameter </param>
        private void ExecuteOnDemandLoading(object obj)
        {
            var node = obj as TreeViewNode;

            // Skip the repeated population of child items when every time the node expands.
            if (node.ChildNodes.Count > 0)
            {
                node.IsExpanded = true;
                return;
            }
            //Animation starts for expander to show progressing of load on demand
            node.ShowExpanderAnimation = true;
            treeViewNodes.Add(node);

            Application.Current.MainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                                  new Action(async() =>
            {
                await Task.Delay(1000);
                foreach (var item in treeViewNodes)
                {
                    if (!item.ShowExpanderAnimation)
                    {
                        continue;
                    }
                    currentNode = item;
                    break;
                }

                MusicInfo musicInfo = currentNode.Content as MusicInfo;

                //Fetching child items to add
                var items = GetSubMenu(musicInfo.ID);

                // Populating child items for the node in on-demand
                currentNode.PopulateChildNodes(items);
                if (items.Count() > 0)
                {
                    //Expand the node after child items are added.
                    currentNode.IsExpanded = true;
                }

                //Stop the animation after load on demand is executed, if animation not stopped, it remains still after execution of load on demand.
                currentNode.ShowExpanderAnimation = false;
                treeViewNodes.Remove(currentNode);
            }));
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            MusicInfo musicInfo = currentNode.Content as MusicInfo;

            //Fetching child items to add
            var items = GetSubMenu(musicInfo.ID);

            // Populating child items for the node in on-demand
            currentNode.PopulateChildNodes(items);
            if (items.Count() > 0)
            {
                //Expand the node after child items are added.
                currentNode.IsExpanded = true;
            }

            //Stop the animation after load on demand is executed, if animation not stopped, it remains still after execution of load on demand.
            currentNode.ShowExpanderAnimation = false;
            timer.Stop();
        }