[英]ObservableCollection.CollectionChanged at design time
public Router() // Router is a ContentControl with [ContentProperty(nameof(Routes))]
{
Routes.CollectionChanged += (sender, args) =>
{
// designer will crash here because NewItems is null...
if (args.NewItems.Count == 0) return;
var route = (Route)args.NewItems[0];
_routesCache[route.Id] = route;
};
}
public ObservableCollection<Route> Routes { get; } = new ObservableCollection<Route>();
CollectionChanged
调用,但args.NewItems
为null
并且collection始终为空。 有什么方法可以在设计时使它可用吗?
<local:Router x:Name="AppRouter">
<local:Route Id="Home" Type="local:Home" />
<local:Route Id="Login" Type="local:Login" />
</local:Router>
我需要在设计时访问这两个Route
对象。
我通过不使用ObservableCollection<T>
来解决它,因为即使在发生Loaded
事件后,项目在设计时始终为空。
我现在只使用List<T>
并访问Loaded
事件处理程序中的路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.