我试图将设备对象列表绑定到我正在处理的服装控件上。我知道这个错误。
“绑定”不能设置在“CamaraSelection”类型的“设备”属性上。“绑定”只能设置在DependencyProperty的DependencyObject上。
xml代码
<trainControl:CamaraSelection Devices="{Binding DeviceList}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>控制码
private List<Device> devices = new List<Device>();
public static readonly DependencyProperty DeviceListProperty =
DependencyProperty.Register("DeviceList", typeof(List<Device>), typeof(CamaraSelection),
new PropertyMetadata(default(ItemCollection), OnDeviceListChanged));
private static void OnDeviceListChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var camaraSelection = dependencyObject as CamaraSelection;
if (camaraSelection != null)
{
camaraSelection.OnDeviceListChanged(dependencyPropertyChangedEventArgs);
}
}
private void OnDeviceListChanged(DependencyPropertyChangedEventArgs e)
{
}
public List<Device> Devices
{
get { return (List<Device>)GetValue(DeviceListProperty); }
set { SetValue(DeviceListProperty, value); }
}发布于 2013-09-11 13:09:19
设置绑定的属性必须是DependencyProperty。在你的例子中,它是Devices-property。DependencyProperty.Register()方法中的第一个参数必须是属性的名称。代码中的第一个参数是"DeviceList",但属性的名称是Devices。
public static readonly DependencyProperty DevicesProperty =
DependencyProperty.Register("Devices", typeof(List<Device>), typeof(CamaraSelection),
new PropertyMetadata(default(ItemCollection), OnDeviceListChanged));
public List<Device> Devices
{
get { return (List<Device>)GetValue(DevicesProperty ); }
set { SetValue(DevicesProperty, value); }
}发布于 2013-09-11 13:09:37
类中的“设备”属性必须是依赖项属性,而不是"DeviceList“。绑定到的属性必须是依赖项属性。
https://stackoverflow.com/questions/18742025
复制相似问题