protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); this.AllowDrop = true; this.Content = containerGrid; ICompositeViewEvents containerEvents = null; bool isDefault = false; this.Loaded += (s, eventArgs) => { isDefault = this.IsDefaultContainer; DependencyObject parent = VisualTreeHelper.GetParent(this); while (null != parent && !typeof(ICompositeViewEvents).IsAssignableFrom(parent.GetType())) { parent = VisualTreeHelper.GetParent(parent); } containerEvents = parent as ICompositeViewEvents; if (null != containerEvents) { if (isDefault) { containerEvents.RegisterDefaultCompositeView(this); } else { containerEvents.RegisterCompositeView(this); } } this.shouldSetFocus = true; if (this.AutoWrapInSequenceEnabled) { // spacer and placer holder this.spacerHelper = new SpacerHelper(this); } }; this.Unloaded += (s, eventArgs) => { if (null != containerEvents) { if (isDefault) { containerEvents.UnregisterDefaultCompositeView(this); } else { containerEvents.UnregisterCompositeView(this); } } this.shouldSetFocus = false; if (this.AutoWrapInSequenceEnabled) { if (this.spacerHelper != null) { this.spacerHelper.Unload(); this.spacerHelper = null; } } }; }