Exemple #1
0
        /// <summary>
        /// Called when the template is changed.
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Unhook existing handlers
            if (null != _splitElement)
            {
                _splitElement.MouseEnter -= new MouseEventHandler(SplitElement_MouseEnter);
                _splitElement.MouseLeave -= new MouseEventHandler(SplitElement_MouseLeave);
                _splitElement             = null;
            }
            if (null != _contextMenu)
            {
                _contextMenu.Opened -= new RoutedEventHandler(ContextMenu_Opened);
                _contextMenu.Closed -= new RoutedEventHandler(ContextMenu_Closed);
                _contextMenu         = null;
            }
#if !SILVERLIGHT
            if (null != _logicalChild)
            {
                RemoveLogicalChild(_logicalChild);
                _logicalChild = null;
            }
#endif

            // Apply new template
            base.OnApplyTemplate();

            // Hook new event handlers
            _splitElement = GetTemplateChild(SplitElementName) as UIElement;
            if (null != _splitElement)
            {
                _splitElement.MouseEnter += new MouseEventHandler(SplitElement_MouseEnter);
                _splitElement.MouseLeave += new MouseEventHandler(SplitElement_MouseLeave);

                _contextMenu = ContextMenuService.GetContextMenu(_splitElement);
                if (null != _contextMenu)
                {
#if !SILVERLIGHT
                    // Add the ContextMenu as a logical child (for DataContext and RoutedCommands)
                    _contextMenu.IsOpen = true;
                    DependencyObject current = _contextMenu;
                    do
                    {
                        _logicalChild = current;
                        current       = LogicalTreeHelper.GetParent(current);
                    } while (null != current);
                    _contextMenu.IsOpen = false;
                    AddLogicalChild(_logicalChild);
#endif

                    _contextMenu.Opened += new RoutedEventHandler(ContextMenu_Opened);
                    _contextMenu.Closed += new RoutedEventHandler(ContextMenu_Closed);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Called when the template is changed.
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Unhook existing handlers
            if (null != _splitElement)
            {
                _splitElement.MouseEnter -= new MouseEventHandler(SplitElement_MouseEnter);
                _splitElement.MouseLeave -= new MouseEventHandler(SplitElement_MouseLeave);
                _splitElement = null;
            }
            if (null != _contextMenu)
            {
                _contextMenu.Opened -= new RoutedEventHandler(ContextMenu_Opened);
                _contextMenu.Closed -= new RoutedEventHandler(ContextMenu_Closed);
                _contextMenu = null;
            }
#if !SILVERLIGHT
            if (null != _logicalChild)
            {
                RemoveLogicalChild(_logicalChild);
                _logicalChild = null;
            }
#endif

            // Apply new template
            base.OnApplyTemplate();

            // Hook new event handlers
            _splitElement = GetTemplateChild(SplitElementName) as UIElement;
            if (null != _splitElement)
            {
                _splitElement.MouseEnter += new MouseEventHandler(SplitElement_MouseEnter);
                _splitElement.MouseLeave += new MouseEventHandler(SplitElement_MouseLeave);

                _contextMenu = ContextMenuService.GetContextMenu(_splitElement);
                if (null != _contextMenu)
                {
#if !SILVERLIGHT
                    // Add the ContextMenu as a logical child (for DataContext and RoutedCommands)
                    _contextMenu.IsOpen = true;
                    DependencyObject current = _contextMenu;
                    do
                    {
                        _logicalChild = current;
                        current = LogicalTreeHelper.GetParent(current);
                    } while (null != current);
                    _contextMenu.IsOpen = false;
                    AddLogicalChild(_logicalChild);
#endif

                    _contextMenu.Opened += new RoutedEventHandler(ContextMenu_Opened);
                    _contextMenu.Closed += new RoutedEventHandler(ContextMenu_Closed);
                }
            }
        }