将 ListBox 的 ItemsSource 绑定(bind)到 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; }
}
当我阅读偷看的代码时,它会爆炸。
这样对吗?
最佳答案
确认错误,重现:
[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);
}
关于c# - WindowsBase.dll 中发生类型为 'System.InvalidCastException' 的第一次机会异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23585430/