1

I am having trouble binding stuff with THIS CONTROL.

I want to create a custom cell template not the default one. When using the default cell template my binding works. Here is my project:

XAML:

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" 
        xmlns:dxt="http://schemas.devexpress.com/winfx/2008/xaml/grid" >
    <Window.Resources>

    </Window.Resources>
    <Grid>
        <dxt:TreeListControl Name="treeList">
            <dxt:TreeListControl.Columns>

                <!-- Custom Column -->
                <dxt:TreeListColumn FieldName="Name" Header="Name">
                    <dxt:TreeListColumn.CellTemplate>
                        <DataTemplate >
                            <TextBlock Text="{Binding Path=Name}" Foreground="Blue" />
                        </DataTemplate>
                    </dxt:TreeListColumn.CellTemplate>                    
                </dxt:TreeListColumn>

                <!-- default Column -->
                <dxt:TreeListColumn FieldName="Position" Header="Position"/>

            </dxt:TreeListControl.Columns>
            <dxt:TreeListControl.View>
                <dxt:TreeListView Name="treeListView1" AutoWidth="True"
                                  KeyFieldName="ID" ParentFieldName="ParentID"/>
            </dxt:TreeListControl.View>
        </dxt:TreeListControl>
    </Grid>
</Window>

Code Behind:

using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;

namespace WpfApplication2
{
    public partial class MainWindow : Window
    {        
        public MainWindow ( )
        {
            InitializeComponent( );
            treeList.ItemsSource = GetStuff( );
            treeListView1.ExpandAllNodes( );
        }

        public static List<Employee> GetStuff ( )
        {
            List<Employee> stuff = new List<Employee>( );

            stuff.Add( new Employee( ) { ID = 1 , ParentID = 0 , Name = "Gregory S. Price" } );
            stuff.Add( new Employee( ) { ID = 2 , ParentID = 0 , Name = "Irma R. Marshall" } );
            stuff.Add( new Employee( ) { ID = 3 , ParentID = 0 , Name = "John C. Powell" } );

            stuff.Add( new Employee( ) { ID = 6 , ParentID = 2 , Position = "Brian C. Cowling" } );
            stuff.Add( new Employee( ) { ID = 7 , ParentID = 2 , Position = "Thomas C. Dawson" } );
            stuff.Add( new Employee( ) { ID = 8 , ParentID = 2 , Position = "Angel M. Wilson" } );
            stuff.Add( new Employee( ) { ID = 9 , ParentID = 2 , Position = "Bryan R. Henderson" } );

            stuff.Add( new Employee( ) { ID = 10 , ParentID = 3 , Position = "Harold S. Brandes" } );
            stuff.Add( new Employee( ) { ID = 11 , ParentID = 3 , Position = "Michael S. Blevins" } );
            stuff.Add( new Employee( ) { ID = 12 , ParentID = 3 , Position = "Jan K. Sisk" } );
            stuff.Add( new Employee( ) { ID = 13 , ParentID = 3 , Position = "Sidney L. Holder" } );

            stuff.Add( new Employee( ) { ID = 14 , ParentID = 1 , Position = "Brian C. Cowling" } );
            stuff.Add( new Employee( ) { ID = 15 , ParentID = 1 , Position = "Thomas C. Dawson" } );
            stuff.Add( new Employee( ) { ID = 16 , ParentID = 1 , Position = "Angel M. Wilson" } );
            stuff.Add( new Employee( ) { ID = 17 , ParentID = 1 , Position = "Bryan R. Henderson" } );


            return stuff;
        }        
    }
}

public class Employee
{
    public int ID { get; set; }
    public int ParentID { get; set; }
    public string Name { get; set; }
    public string Position { get; set; }
}

why is it that my (<!-- Custom Column -->) does not display the Name of the employe? what do I have to do to bind it to that Property? If I remove the CellTemplate it works but I want to have my custom style...

Tono Nam
  • 34,064
  • 78
  • 298
  • 470

1 Answers1

3

Ok I'm going to answer before Devex Team :)

Change this :

<TextBlock Text="{Binding Path=Name}" Foreground="Blue" />

To this :

<TextBlock Text="{Binding Path=Data.Name}" Foreground="Blue" />

Or simply :

<TextBlock Text="{Binding Data.Name}" Foreground="Blue" />
Abdusalam Ben Haj
  • 5,343
  • 5
  • 31
  • 45