0

如何绑定 DataGridTextColumn 内的列表属性以绑定主窗口中的列表。

为此,我使用

public class DataGridListBoxColumn : DataGridTextColumn
    {
        TextBlock tx = new TextBlock();

        public DataGridListBoxColumn()
        {
            tx.Name = "TxB";
        }
        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, Object dataItem)
        {
            Binding b = new Binding();
            b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(DataGridListBoxColumn), 1);
            b.Path = new PropertyPath("ListItem");
            tx.SetBinding(TextBlock.TextProperty, b);
            return cell;
        }
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var x = ListItem;
            Debugger.Break(); //here x is null 
        }

        public List<Student> ListItem
        {
            get { return (List<Student>)GetValue(ItemSourceProperty); }
            set { SetValue(ItemSourceProperty, value); }
        }
        public static readonly  DependencyProperty ItemSourceProperty = DependencyProperty.Register("ListItem", typeof(List<Student>), typeof(DataGridListBoxColumn));

    }

我将 TextBlock 用作隐藏仅用于绑定目的。

如何将列表绑定传递给 DataGridTextColumn?

4

0 回答 0