コード例 #1
0
        /// <summary>
        /// Called after the behavior is attached to an AssociatedObject.
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();
            _popupHeader = new PopupHeader();
            _popupHeader.PlacementTarget = AssociatedObject;
            var content = new ContentPresenter {
                ContentTemplate = HeaderTemplate, HorizontalAlignment = HorizontalAlignment.Stretch
            };

            _popupHeader.Content = content;

            if (AssociatedObject is Panel)
            {
                SetPanelRoot(AssociatedObject, AssociatedObject as Panel);
            }
            else
            {
                var binding = new Binding();
                binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor)
                {
                    AncestorType = typeof(Panel)
                };
                BindingOperations.SetBinding(AssociatedObject, PanelRootProperty, binding);
            }

            var panel = GetPanelRoot(AssociatedObject);

            panel.Children.Add(_popupHeader);
        }
コード例 #2
0
        /// <summary>
        /// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.
        /// </summary>
        protected override void OnDetaching()
        {
            base.OnDetaching();

            var panel = GetPanelRoot(AssociatedObject);

            panel.Children.Remove(_popupHeader);

            _popupHeader.PlacementTarget = null;
            _popupHeader = null;
        }