Beispiel #1
0
        /// <summary>
        /// Overrides the OnApplyTemplate method.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

              if( _windowControl != null )
              {
            _windowControl.HeaderDragDelta -= ( o, e ) => this.OnHeaderDragDelta( e );
            _windowControl.HeaderIconDoubleClicked -= ( o, e ) => this.OnHeaderIconDoubleClicked( e );
            _windowControl.CloseButtonClicked -= ( o, e ) => this.OnCloseButtonClicked( e );
              }
              _windowControl = this.GetTemplateChild( PART_WindowControl ) as WindowControl;
              if( _windowControl != null )
              {
            _windowControl.HeaderDragDelta += ( o, e ) => this.OnHeaderDragDelta( e );
            _windowControl.HeaderIconDoubleClicked += ( o, e ) => this.OnHeaderIconDoubleClicked( e );
            _windowControl.CloseButtonClicked += ( o, e ) => this.OnCloseButtonClicked( e );
              }
              this.UpdateBlockMouseInputsPanel();

              ChangeVisualState( _button.ToString(), true );

              Button closeButton = GetMessageBoxButton( PART_CloseButton );
              if( closeButton != null )
            closeButton.IsEnabled = !object.Equals( _button, MessageBoxButton.YesNo );

              Button okButton = GetMessageBoxButton( PART_OkButton );
              if( okButton != null )
            okButton.IsCancel = object.Equals( _button, MessageBoxButton.OK );

              SetDefaultResult();
        }
 private void SetChildPos( WindowControl windowControl )
 {
     // A MessageBox with no X and Y will be centered.
       // A ChildWindow with WindowStartupLocation == Center will be centered.
       if( ( ( windowControl is MessageBox ) && ( windowControl.Left == 0 ) && ( windowControl.Top == 0 ) )
     || ( ( windowControl is ChildWindow ) && ( ( ( ChildWindow )windowControl ).WindowStartupLocation == WindowStartupLocation.Center ) ) )
       {
     this.CenterChild( windowControl );
       }
       else
       {
     Canvas.SetLeft( windowControl, windowControl.Left );
     Canvas.SetTop( windowControl, windowControl.Top );
       }
 }
        private void SetNextActiveWindow( WindowControl windowControl )
        {
            if( !this.IsLoaded )
            return;

              WindowControl modalWindow = this.GetModalWindow();
              // Modal window is always in front
              if( modalWindow != null )
              {
            this.BringToFront( modalWindow );
              }
              else if( windowControl != null )
              {
            this.BringToFront( windowControl );
              }
              else
              {
            this.BringToFront( this.Children.OfType<WindowControl>().FirstOrDefault( (x) => x.Visibility == Visibility.Visible ) );
              }
        }
 private bool IsModalWindow( WindowControl windowControl )
 {
     return ( ( windowControl is MessageBox )
      || ( ( windowControl is ChildWindow ) && ( ( ChildWindow )windowControl ).IsModal ) );
 }
 private void SetActiveWindow( WindowControl windowControl )
 {
     foreach( WindowControl window in this.Children )
       {
     window.SetIsActiveInternal( false );
       }
       windowControl.SetIsActiveInternal( true );
 }
        private double GetRestrictedTop( WindowControl windowControl )
        {
            if( windowControl.Top < 0 )
            return 0;

              if( ( ( windowControl.Top + windowControl.ActualHeight ) > this.ActualHeight ) && ( this.ActualHeight != 0 ) )
              {
            double y = this.ActualHeight - windowControl.ActualHeight;
            return y < 0 ? 0 : y;
              }

              return windowControl.Top;
        }
        private double GetRestrictedLeft( WindowControl windowControl )
        {
            if( windowControl.Left < 0 )
            return 0;

              if( ( ( windowControl.Left + windowControl.ActualWidth ) > this.ActualWidth ) && ( this.ActualWidth != 0 ) )
              {
            double x = this.ActualWidth - windowControl.ActualWidth;
            return x < 0 ? 0 : x;
              }

              return windowControl.Left;
        }
 private void CenterChild( WindowControl windowControl )
 {
     if( ( windowControl.ActualWidth != 0 ) && ( windowControl.ActualHeight != 0 ) )
       {
     windowControl.Left = ( this.ActualWidth - windowControl.ActualWidth ) / 2.0;
     windowControl.Top = ( this.ActualHeight - windowControl.ActualHeight ) / 2.0;
       }
 }
        private void BringToFront( WindowControl windowControl )
        {
            if( windowControl != null )
              {
            int maxZIndez = this.Children.OfType<WindowControl>().Max( ( x ) => Canvas.GetZIndex( x ) );
            Canvas.SetZIndex( windowControl, maxZIndez + 1 );

            windowControl.Focus();

            this.SetActiveWindow( windowControl );
              }
        }
Beispiel #10
0
    public override void OnApplyTemplate()
    {
      base.OnApplyTemplate();

      if( _windowControl != null )
      {
        _windowControl.HeaderDragDelta -= ( o, e ) => this.OnHeaderDragDelta( e );
        _windowControl.HeaderIconDoubleClicked -= ( o, e ) => this.OnHeaderIconDoubleClick( e );
        _windowControl.CloseButtonClicked -= ( o, e ) => this.OnCloseButtonClicked( e );
      }
      _windowControl = this.GetTemplateChild( PART_WindowControl ) as WindowControl;
      if( _windowControl != null )
      {
        _windowControl.HeaderDragDelta += ( o, e ) => this.OnHeaderDragDelta( e );
        _windowControl.HeaderIconDoubleClicked += ( o, e ) => this.OnHeaderIconDoubleClick( e );
        _windowControl.CloseButtonClicked += ( o, e ) => this.OnCloseButtonClicked( e );
      }

      this.UpdateBlockMouseInputsPanel();

      _windowRoot = this.GetTemplateChild( PART_WindowRoot ) as Grid;
      _windowRoot.RenderTransform = _moveTransform;
      _hasWindowContainer = ( VisualTreeHelper.GetParent( this ) as WindowContainer ) != null;

      if( !_hasWindowContainer )
      {
        _parentContainer = VisualTreeHelper.GetParent( this ) as FrameworkElement;
        if( _parentContainer != null )
        {
          _parentContainer.LayoutUpdated += ParentContainer_LayoutUpdated;
          _parentContainer.SizeChanged += ParentContainer_SizeChanged;

          //this is for XBAP applications only. When inside an XBAP the parent container has no height or width until it has loaded. Therefore
          //we need to handle the loaded event and reposition the window.
          if( System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted )
          {
            _parentContainer.Loaded += ( o, e ) =>
            {
              ExecuteOpen();
            };
          }
        }

        this.Unloaded += new RoutedEventHandler( ChildWindow_Unloaded );

        //initialize our modal background width/height
        _modalLayer.Height = _parentContainer.ActualHeight;
        _modalLayer.Width = _parentContainer.ActualWidth;

        _root = this.GetTemplateChild( PART_Root ) as Grid;

#if VS2008
      FocusVisualStyle = null;
#else
        Style focusStyle = _root.Resources[ "FocusVisualStyle" ] as Style;
        if( focusStyle != null )
        {
          Setter focusStyleDataContext = new Setter( Control.DataContextProperty, this );
          focusStyle.Setters.Add( focusStyleDataContext );
          FocusVisualStyle = focusStyle;
        }
#endif
        _root.Children.Add( _modalLayerPanel );
      }
    }