1

THIS CONTROLで何かをバインドするのに問題があります。

デフォルトのセル テンプレートではなく、カスタム セル テンプレートを作成したいと考えています。デフォルトのセル テンプレートを使用すると、バインディングが機能します。これが私のプロジェクトです:

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>

コードビハインド:

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; }
}

私の ( <!-- Custom Column -->) に従業員の名前が表示されないのはなぜですか? そのプロパティにバインドするにはどうすればよいですか? CellTemplate を削除すると機能しますが、カスタムスタイルが必要です...

4

1 に答える 1

3

わかりました、私はDevexチームの前に答えるつもりです:)

これを変える :

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

これに:

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

または単に:

<TextBlock Text="{Binding Data.Name}" Foreground="Blue" />
于 2013-02-06T16:50:56.530 に答える