【发布时间】:2018-12-20 03:55:59
【问题描述】:
我想将一个列表对象传递给我的数据网格 DataGridTextColumn 的自定义控件。 为此我使用了这段代码
public class DataGridListBoxColumn : DataGridTextColumn
{
public IList<Student> ListItems
{
get { return (IList<Student>)GetValue(_ListItems); }
set { SetValue(_ListItems, value); }
}
public static readonly DependencyProperty _ListItems = DependencyProperty.Register("ListItems", typeof(IList<Student>), typeof(DataGridListBoxColumn));
}
我的 XAML
<local:DataGridListBoxColumn Binding="{Binding M_Name,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" ListItems="{Binding Path= stud, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}" Width="100"/>
或
<local:DataGridListBoxColumn Binding="{Binding M_Name,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" ListItems="{Binding RelativeSource={RelativeSource AncestorType=DataGridTextColumn}, Path=stud}" Width="100"/>
两者都不起作用,有什么方法可以将列表传递给我的自定义控件 谢谢
【问题讨论】:
-
stud在哪里? -
@Rekshino 对不起,但你是对的。似乎我不明白 XAML 解析器如何处理绑定...... OP 仍应遵守此命名约定。我确信我见过由于错误命名的标识符字段而导致绑定不起作用的情况。
-
@Clemens 没问题! :) 正如我所说,这是我的第一个猜测,你是对的,该约定是命名 abcProperty。
标签: wpf custom-controls dependency-properties listobject