WPF: In an attached property, how to wait until visual tree loaded properly?
问题 I have an Attached Property in a WPF app. The code below is inside the OnLoad event, but it doesn't work unless I add a hacky 500 millisecond delay in. Is there some way to avoid this delay, and detect when the visual tree has been loaded? private static void FrameworkElement_Loaded(object sender, RoutedEventArgs e) { // ... snip... Window window = GetParentWindow(dependencyObject); // Without this delay, changing properties does nothing. Task task = Task.Run( async () => { { // Without this