Autor Beitrag
Greenberet
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 339
Erhaltene Danke: 20

Win 10
C# (VS 2012), C++ (VS 2012/GCC), PAWN(Notepad++), Java(NetBeans)
BeitragVerfasst: Fr 27.07.07 18:07 
Hi,
ich hoffe ihr könnt mir helfen. Ich habe ein TreeView mit einem HierarchicalDataTemplate. Mein Problem ist, dass immer nur 2 Hierachien angezeigt werden, also meine Hauptliste und deren Subelemente. Allerdings haben meine Subelemente ebenfalls wieder subelemente die wiederum subelemente haben können usw. Nur diese werden wie gesagt nicht angezeigt.

Vielleicht findet ihr ja meinen fehler.

TreeView im XAML
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
    <TreeView x:Name="tvFiles">
      <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Path=ChildFileFolders}">
          <TextBlock FontWeight="Bold" Text="{Binding Path=Text}" />
          
          <HierarchicalDataTemplate.ItemTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding Path=Text}"/>
            </DataTemplate>
          </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>
      </TreeView.ItemTemplate>
    </TreeView>


Meine Items Klasse:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
    /// <summary>
    /// Implements the FileFolder class to display an logical FolderTree
    /// </summary>
    public class FileFolder
    {
        #region Fields
        Collection<FileFolder> childFileFolders;
        string text;
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor of this class
        /// </summary>
        public FileFolder()
        {
            this.childFileFolders = new Collection<FileFolder>();
        }

        /// <summary>
        /// Constructor of this class
        /// </summary>
        /// <param name="text">will set the Text property</param>
        public FileFolder(string text) : this()
        {
            this.text = text;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Get the collection with all childelements
        /// </summary>
        public Collection<FileFolder> ChildFileFolders
        {
            get
            {
                return this.childFileFolders;
            }
        }

        /// <summary>
        /// Set/Get the Text of this entry
        /// </summary>
        public string Text
        {
            get { return this.text; }
            set { this.text = value; }
        }
        #endregion
    }


Und hier noch die zuweisung der Elemente:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
            Collection<FileFolder> list = new Collection<FileFolder>();
            FileFolder root = new FileFolder();
            FileFolder rootChild1 = new FileFolder();
            FileFolder rootChild2 = new FileFolder();
            FileFolder rootSubChild1 = new FileFolder();

            root.Text = "root";
                rootChild1.Text = "rootChild1";
                    rootSubChild1.Text = "rootSubChild1";
                    rootChild1.ChildFileFolders.Add(rootSubChild1);
                rootChild2.Text = "rootChild2";
                root.ChildFileFolders.Add(rootChild2);
                root.ChildFileFolders.Add(rootChild1);
            list.Add(root);
            tvFiles.ItemsSource = list;
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 27.07.07 18:22 
Versuch mal, das <HierarchicalDataTemplate.ItemTemplate> ... </HierarchicalDataTemplate.ItemTemplate> wegzulassen. Das kommt mir irgendwie komisch vor.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Greenberet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 339
Erhaltene Danke: 20

Win 10
C# (VS 2012), C++ (VS 2012/GCC), PAWN(Notepad++), Java(NetBeans)
BeitragVerfasst: Fr 27.07.07 18:29 
ah danke dass war der fehler^^