WPF Behavior AssociatedObject is null
问题 I'm setting a behavior on my control (in xaml), the behavior has the following code: protected override void OnAttached() { base.OnAttached(); AssociatedObject.Loaded += OnMycontrolLoaded; AssociatedObject.Unloaded += OnMycontrolUnloaded; } private void OnMycontrolLoaded(object sender, RoutedEventArgs e) { AssociatedObject.MyEvent +=MyEventHandler; } protected override void OnDetaching() { base.OnDetaching(); AssociatedObject.Loaded -= OnMycontrolLoaded; AssociatedObject.Unloaded -=