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 8616205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:33:44+00:00 2026-06-12T05:33:44+00:00

I have a WPF treeview. Here is the code: <DockPanel Grid.Row=2 Margin=0,6,0,0 Grid.RowSpan=5 Height=491

  • 0

I have a WPF treeview. Here is the code:

<DockPanel Grid.Row="2" Margin="0,6,0,0" Grid.RowSpan="5" Height="491" VerticalAlignment="Top">
        <DockPanel.Resources>

            <src:TreeViewFilter x:Key="MyList" />

            <HierarchicalDataTemplate DataType="{x:Type src:TreeViewParent}" ItemsSource="{Binding Path=OrderAttributes}">
                <TextBlock Text="{Binding Path=Name}" FontSize="16"/>
            </HierarchicalDataTemplate>

            <HierarchicalDataTemplate DataType="{x:Type src:OrderAttribute}" ItemsSource="{Binding Path=OrderAttributes}">
                <TextBlock Text="{Binding Path=NameAndCount}" />
            </HierarchicalDataTemplate>

        </DockPanel.Resources>
        <TreeView Name="treeView1" Height="490" Width="235" VerticalAlignment="Top" ItemsSource="{Binding Source={StaticResource MyList}, UpdateSourceTrigger=PropertyChanged}" TreeViewItem.Selected="treeViewFilter" />
    </DockPanel>

The Treeview binds to the static resource MyList and TreeViewParents Objects are created in the TreeViewFilter class: (removed some unnecessary SQL code to retrieve data).

public class TreeViewFilter : ObservableCollection<TreeViewParent>
{
    //three tree view parents that wont change
    public TreeViewParent allOrders;
    public TreeViewParent batchStatus;
    public TreeViewParent shippedOrders;
    static TreeViewFilter currentInstance1; //maybe set to null, can only create one instance!

    public TreeViewFilter()
    {

        currentInstance1 = this;

        //Create and fill out all orders tree filter
        Add(allOrders = new TreeViewParent("All Orders", 0));

        //Create and fill out batch status tree filter
        Add(batchStatus = new TreeViewParent("Batch Status", 0));
        int untouchedCount, batchReadyCount, errorCount;

        OrderAttribute untouched = new OrderAttribute("Untouched", "Batch Status", 3, untouchedCount);
        OrderAttribute batchReady = new OrderAttribute("Batch Ready", "Batch Status", 3, batchReadyCount);
        OrderAttribute error = new OrderAttribute("Error", "Batch Status", 3, errorCount);
        batchStatus.OrderAttributes.Add(untouched);
        batchStatus.OrderAttributes.Add(batchReady);
        batchStatus.OrderAttributes.Add(error);

        OrderManager currentInstance = OrderManager.getCurrentInstance();
    }

    public static TreeViewFilter getCurrentInstance()
    {
        return currentInstance1;
    }
}

Then the treeview parents bind to Order Attributes. Order Attributes can have there own collection of Order Attributes as well. (hierarchical filtering tree view)

Here is the TreeViewParent and OrderAttribute Code: (both are similiar)

public class Base
{
    public int classIdentifier;
}

public class TreeViewParent : Base
{
static TreeViewParent currentInstance;

    public TreeViewParent(string name, int classIdent)
    {
        this._name = name;
        this._orderAttributes = new ObservableCollection<OrderAttribute>();
        classIdentifier = classIdent;
        currentInstance = this;
    }

    public string _name;

    public string Name { get { return _name; } }

    ObservableCollection<OrderAttribute> _orderAttributes;
    public ObservableCollection<OrderAttribute> OrderAttributes 
    { 
        get { return _orderAttributes; }
    }

    public static TreeViewParent getCurrentInstance()
    {
        return currentInstance;
    }
}

public class OrderAttribute : Base
{
public string parentFilter;
static OrderAttribute currentInstance;

    public OrderAttribute(string name, string parent, int classIdent)
    {
        _name = name;
        parentFilter = parent;
        classIdentifier = classIdent;
        _orderAttributes = new ObservableCollection<OrderAttribute>();
        currentInstance = this;
    }

    public OrderAttribute(string name, string parent, int classIdent, int count)
    {
        _name = name;
        parentFilter = parent;
        classIdentifier = classIdent;
        _count = count;
        currentInstance = this;
    }

    string _name;
    public int _count = 0;

    public string Name { get { return _name; } }

    public string NameAndCount
    {
        get
        {
            if (_count == 0)
            {
                return _name;
            }
            else
            {
                return _name + " (" + _count + ")";
            }
        }
    }

    ObservableCollection<OrderAttribute> _orderAttributes;
    public ObservableCollection<OrderAttribute> OrderAttributes { get { return _orderAttributes; } }

    public static OrderAttribute getCurrentInstance()
    {
        return currentInstance;
    }
}

How can i use dependency objects to have updated NameAndCount data be displayed and changed dynamically as the program runs and counts change?

  • 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-06-12T05:33:46+00:00Added an answer on June 12, 2026 at 5:33 am

    The view should now when and how the NameAndCount property of an OrderAttribute object changed.

    You have to implement INotifyPropertyChanged interface and raise PropertyChanged event every time when you want to send notification to your view.

    In your example when the _count fields value changes.

    public OrderAttribute : Base, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    
        private int _count = 0;
    
        public int Count
        {
            get { return _count; }
            set 
            {
                 if(_count != value)
                 {
                     _count = value;
                     FirePropertyChanged("NameAndCount");
                 }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In WPF, I have a custom control that inherits from TreeView. The code is
I have the next WPF treeview: <TreeView HorizontalAlignment=Left Margin=6,0,0,32 Name=tvProductos Width=158> <TreeViewItem Header=Securities IsExpanded=True
I have a WPF window with a Grid and a TreeView. The datacontext for
I have a basic C# WPF TreeView, but I do not like that the
I have a treeview in wpf and I load it ok is all done
I have a hierarchical treeview in WPF. I use http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/ for eventbinding with the
In my WPF application, I have a treeview. This treeview is bound to a
I have WPF Form which has many buttons with the same code. Appearance of
I currently have a strange memory leak with WPF TreeView. When I select an
I have a custom class that I would like to bind a WPF TreeView

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.