我在将ListBox的ItemsSource绑定到ObservableCollection<object>
时遇到此异常。
该集合填充了{DependencyPropertyChangedEventArgs,EventEntry}
我偷看了DependencyPropertyChangedEventArgs
并找到了:
public struct DependencyPropertyChangedEventArgs
{
...
public override bool Equals(object obj)
{
return this.Equals((DependencyPropertyChangedEventArgs)obj); <- huge cast right here?
}
}
EventEntry代码:
public class EventEntry
{
public EventEntry(string name)
{
Name = name;
}
public string Name { get; private set; }
}
当我阅读偷看的代码时,它被设计为爆炸。
这是对的吗?
答案 0 :(得分:0)
确认错误,repro:
[Test]
public void Repro()
{
var args = new DependencyPropertyChangedEventArgs(UIElement.IsEnabledProperty, false, true);
Assert.Throws<InvalidCastException>(() => args.Equals(1));
}
Confirmed bug in the implementation: (below code is from reference source)
public override bool Equals(object obj)
{
return Equals((DependencyPropertyChangedEventArgs)obj);
}