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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:26:08+00:00 2026-06-12T03:26:08+00:00

I have a TreeViewItem where I am using a TextBlock for the Header property

  • 0

I have a TreeViewItem where I am using a TextBlock for the Header property and a custom class as the Tag property. How do I go about creating a copy of the TreeViewItem? I’ve tried serializing it, but it keeps going into an infinite loop, creates a Stack OverFlow Exception, when it tries to serialize the TreeViewItem, but I can’t find out where.

This is the custom class I am using as a Tag property for my TreeViewItem

 [Serializable]
 [XmlRoot(ElementName="TVITagProperty")]
 public class TVITagProperty {
      #region Members
      /// <summary>
      /// Tree Type
      /// </summary>
      public enum TreeType {
           User = 1,
           Other = 2,
      }

      /// <summary>
      /// Tag Property Type
      /// </summary>
      public enum TagType {
           Entity = 1,
           User = 2,
      };
      #endregion

      #region C'tor
      /// <summary>
      /// Public parameterless constructor
      /// </summary>
      public TVITagProperty() { }

      /// <summary>
      /// Create a TreeViewItem Tag Property
      /// </summary>
      /// <param name="type">Type of Tag Property</param>
      /// <param name="value">Value of Tag Property</param>
      public TVITagProperty(TreeType treeType, TagType tagType, string value) {
           ViewType = treeType;
           PropertyType = tagType;
           PropertyValue = value;
           PropertyDirectory = false;
      }

      /// <summary>
      /// Create a TreeViewItem Tag Property
      /// </summary>
      /// <param name="type">Type of Tag Property</param>
      /// <param name="value">Value of Tag Property</param>
      public TVITagProperty(TagType type, long? value) {
           PropertyType = type;
           PropertyValue = value.ToString();
      }
      #endregion

      #region Methods
      /// <summary>
      /// Overloaded Equals method, compares one TVI Tag Property Property Type and Value
      /// </summary>
      /// <param name="obj"></param>
      /// <returns></returns>
      public bool Equals(TVITagProperty obj) {
           if(obj != null) {
                if(obj.PropertyDirectory == true) {
                     if(this.ViewType == obj.ViewType &&
                          this.PropertyType == obj.PropertyType) {
                          return true;
                     }
                }
                else if(this.ViewType == obj.ViewType &&
                     this.PropertyType == obj.PropertyType &&
                     this.PropertyValue.Equals(obj.PropertyValue)) {
                     return true;
                }
           }
           return false;
      }

      /// <summary>
      /// Overrides ToString() and returns Property value
      /// </summary>
      /// <returns></returns>
      public override string ToString() {
           return this.PropertyValue;
      }

      /// <summary>
      /// Returns the Property value as a long
      /// </summary>
      /// <returns></returns>
      public long ToLong() {
           return long.Parse(this.PropertyValue);
      }
      #endregion

      #region Properties
      /// <summary>
      /// Represents the type of TreeView used in the View
      /// </summary>
      [XmlAttribute]
      public TreeType ViewType { get; set; }
      /// <summary>
      /// The type of Property Tag
      /// </summary>
      [XmlAttribute]
      public TagType PropertyType { get; set; }
      /// <summary>
      /// The value of Property Tag
      /// </summary>
      [XmlAttribute]
      public string PropertyValue { get; set; }
      /// <summary>
      /// Defines whether the TVI is an object or directory
      /// </summary>
      [XmlAttribute]
      public bool PropertyDirectory { get; set; }
      #endregion
 }
  • 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-12T03:26:09+00:00Added an answer on June 12, 2026 at 3:26 am

    Creating a copy of a wpf TreeViewItem seems like the wrong approach – why do you want to do that?

    A better way is to not generate any treeviewitems yourself but let wpf handle it via a hierachical template and itemsource -then you can make copies of your objects in your itemssource and wpf will render them for you.

    see for example this:

    WPF: Correctly storing an object in a TreeViewItem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class derived from TreeviewItem(Custom TreeViewItem) which is used by a class
I have successfully used a few custom commands using MVVM-Light, but I want my
I have the following code. My TreeViewItem: class ComponenteNodoViewModel : BaseViewModel { public string
I have the next WPF treeview: <TreeView HorizontalAlignment=Left Margin=6,0,0,32 Name=tvProductos Width=158> <TreeViewItem Header=Securities IsExpanded=True
So I have tried a whole bunch of examples from google, but I cannot
have written this little class, which generates a UUID every time an object of
Problem I have a Silverlight 5 application using the treeview from the SDK. Now
I am creating a TreeView at runtime. It has several nodes(TreeViewItem), each one having
I have TreeViewItem s where the HierarchicalDataTemplate consists of a Grid with 3 columns
Greetings, I'm using WPF with a Model-View-ViewModel pattern, and I have a view model

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.