Incorrect display of data

rammfire

Member
Joined
Sep 1, 2020
Messages
14
Programming Experience
Beginner
I have a class that describes the level of subordination of departments:
C#:
public class SeniorPosition : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;


        private string managementPositionName;


        private string whoReportsToTheDepartment;


        public string ManagementPositionName
        {
            get
            {
                return managementPositionName;
            }
            set
            {
                managementPositionName = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(managementPositionName)));
            }
        }


        public string WhoReportsToTheDepartment
        {
            get
            {
                return whoReportsToTheDepartment;
            }
            set
            {
                whoReportsToTheDepartment = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WhoReportsToTheDepartment)));
            }
        }

        public SeniorPosition(string formalManagePositionName, string formalWhoReportsToTheDepartment)
        {
            ManagementPositionName = formalManagePositionName;
            WhoReportsToTheDepartment = formalWhoReportsToTheDepartment;
        }
    }

And implemented binding:
XML:
 <TreeView Grid.Row="1" Name="DepartamentHierarchy">
          <TreeView.Resources>
                  <HierarchicalDataTemplate DataType="{x:Type local:SeniorPosition}" ItemsSource="{Binding ManagementPositionName}">
                         <TextBlock Text="{Binding WhoReportsToTheDepartment}"/>
                   </HierarchicalDataTemplate>
            </TreeView.Resources>
   </TreeView>

At the output I get the following oddity
1608134669967.png

the main elements of the tree are displayed correctly, and the child elements are displayed character-by-character. How can I fix this?
 
I'm going to quote @Sheepings stock response: "put it in a grid cell". :)

Seriously, though, check on the size and alignment settings of the column and row of that grid cell that your treeview is in.
 
as i understand it, this is due to the fact that textblock in this particular case sees the string as an array of char. As I understand it, it will be better to use Observablecollection, but I'm so lazy to rewrite all this.
 
Back
Top Bottom