Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3874424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:09:00+00:00 2026-05-19T22:09:00+00:00

I have a following problem. I have some items in my treeview which are

  • 0

I have a following problem. I have some items in my treeview which are at the top of hierarchy. When I click on some item to expand it, it can event take 5 seconds to load all items in selected node. How can show “Please wait…expanding node..” message during this process? How can I determine whether item is still expanding or all nested items are loaded and presented now?

I have already asked very similar question here Show "Please wait.." message when expanding TreeView in WPF, I even mark the answer as accepted but however, the solution I have now is not satisfactory because “Please wait..” dialog is blinking (it’s shown and closed as many times as number of nested items).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:09:01+00:00Added an answer on May 19, 2026 at 10:09 pm

    As I’ve mentioned in comment to your post, two problems may exists we need to solve.

    1. You have a lot of items, so when you expand node – wpf begins to generate item containers and put them into visual tree. It could be annoying.
    2. On the other hand, I suppose next scenario – user expand node item and you send request to database/remote server which may execute some time.

    WPF doesn’t provide BeforeExpand event, so you should use view data, notifications on property changed, data binding and observable collections. I’ll illustrate this in simple application.

    The whole approach can be approximately described as:

    • Bind IsExpanded property of view data to IsExpanded property of TreeViewItem
    • Listen IsExpanded property changed notifications somewhere (may be in model)
    • Set up IsLoading property (in my sapmle it is declared in view data)
    • Start some task that fills inner items
    • Reset IsLoading property
    • Put DataTrigger in xaml, which reacts on IsLoading property.

    I’ve designed my tree item ViewData class with observable properties IsExpanded, IsLoaded, observable collection of children items and Name that will be displayed:

    public class TreeItem : ObservableObject
    {
        public TreeItem (string name)
        {
            this.Name = name;
        }
    
        public string Name 
        {
            get; 
            private set; 
        }
    
        private bool _isExpanded;
        public bool IsExpanded
        {
            get
            {
                return this._isExpanded;
            }
            set
            {
                if (this._isExpanded != value)
                {
                    this._isExpanded = value;
                    this.OnPropertyChanged("IsExpanded");
                }
            }
        }
    
        private bool _isLoading;
        public bool IsLoading
        {
            get
            {
                return this._isLoading;
            }
            set
            {
                if (this._isLoading != value)
                {
                    this._isLoading = value;
                    this.OnPropertyChanged("IsLoading");
                }
            }
        }
    
    
        private ObservableCollection<TreeItem> _innerItems = new ObservableCollection<TreeItem>();
        public IEnumerable<TreeItem> InnerItems
        {
            get
            {
                return this._innerItems;
            }
    
        }
    
        public void LoadInnerItems()
        {
            this.IsLoading = true;
            var sc= SynchronizationContext.Current;
            new Thread(new ThreadStart(() => 
                {
                    Thread.Sleep(5000);
                    sc.Send(o =>
                        {
                            this._innerItems.Add(new TreeItem("1223"));
                            this._innerItems.Add(new TreeItem("2345"));
                            this._innerItems.Add(new TreeItem("666678"));
                            this.IsLoading = false;
                        }, null);
                }))
                .Start();
        }
    }
    

    Next step consists in developing Presentation Model. As you can see our model listens to IsExpanded PropertyChanged event and when it equals to true start LoadingInnerItems.:

    public class SampleModel : ObservableObject
    {
        public SampleModel()
        {
            this._items.Add(new TreeItem("AAA"));
            this._items.Add(new TreeItem("BBB"));
            this._items.Add(new TreeItem("CCC"));
    
            foreach (var i in this._items)
            {
                i.PropertyChanged += new PropertyChangedEventHandler(Item_PropertyChanged);
            }
    
        }
    
        void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "IsExpanded")
            {
                var item = (TreeItem)sender;
                if(item.IsExpanded)
                {
                    item.LoadInnerItems();
                }
            }
        }
    
        private ObservableCollection<TreeItem> _items = new ObservableCollection<TreeItem>();
        public IEnumerable<TreeItem> Items
        {
            get
            {
                return this._items;
            }
        }
    }
    

    XAML for our TreeView. When we are loading inner items – foreground of our treeviewitem goes red:

    <TreeView ItemsSource="{Binding Items}">
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding InnerItems}">
                <TextBlock Text="{Binding Name}"/>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
        <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem">
                <Setter Property="IsExpanded"
                        Value="{Binding IsExpanded, Mode=TwoWay}"/>
                <Setter Property="Foreground"
                        Value="Aqua"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsLoading}"
                                 Value="True">
                        <Setter Property="Foreground" 
                                Value="Red"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
    

    And don’t forget set model as datacontext of view in code behind:

        public MainWindow()
        {
            InitializeComponent();
    
            this.Model = new SampleModel();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I have some Excel-sheets and must export them into
Hi i have following Problem. I write a Mediawiki Extension where i need some
I have the following problem with Tikz/Latex: I have some nodes that contain text.
Propose to consider the following problem. Suppose we have some composite object. Are there
i am new in JSP,i have some problem with the following code : <%@
I found the following lines in a makefile tutorial, but I have some problem
I have the following problem in application express which is driving me crazy: I
I have the following code which does nothing but reading some values from a
I have a problem with the following code, which doesn't want to work in
I have the following problem: I have a given number of identically formed items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.