[英]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.