我有一个以列表为成员的派生面板。如何从 xaml 绑定到列表?
class mypanel : Panel
{
IList<int> mylist;
...
}
编辑:
public static DependencyProperty myListProperty;
myListProperty= DependencyProperty.RegisterAttached("ListSource", typeof(IList<int>), typeof(mypanel));
var b = new Binding("ListSource") { Source = myList, Mode = BindingMode.TwoWay };
SetBinding(LayerSourceProperty, b);
解决方案:以下事情有效..
public static DependencyProperty myListProperty=
DependencyProperty.Register("ListSource", typeof(IList<int>), typeof(mypanel), new FrameworkPropertyMetadata(mylistchanged));
private static void LayerSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var obj = (mypanel) d;
.......
}