private void LoadBanner()
      {
         // LOAD the startup banner only when it's set (instead of removing it after)
         if (Settings.Default.StartupBanner && System.IO.File.Exists("StartupBanner.xaml"))
         {
            try
            {
               Paragraph banner;
               ErrorRecord error;
               var startup = new System.IO.FileInfo("StartupBanner.xaml");
               if (startup.TryLoadXaml(out banner, out error))
               {
                  // Copy over *all* resources from the DOCUMENT to the BANNER
                  // NOTE: be careful not to put resources in the document you're not willing to expose
                  // NOTE: this will overwrite resources with matching keys, so banner-makers need to be aware
                  foreach (string key in this.buffer.Document.Resources.Keys)
                  {
                     banner.Resources[key] = this.buffer.Document.Resources[key];
                  }
                  banner.Padding = new Thickness(5);
                  this.buffer.Document.Blocks.InsertBefore(this.buffer.Document.Blocks.FirstBlock, banner);
               }
               else
               {
                  ((IPSConsole)this.buffer).WriteLine("PoshConsole 2.1.2011.520");
               }

               // Document.Blocks.InsertBefore(Document.Blocks.FirstBlock, new Paragraph(new Run("PoshConsole`nVersion 1.0.2007.8150")));
               // Document.Blocks.AddRange(LoadXamlBlocks("StartupBanner.xaml"));
            }
            catch (Exception ex)
            {
               Trace.TraceError(@"Problem loading StartupBanner.xaml\n{0}", ex.Message);
               this.buffer.Document.Blocks.Clear();
               ((IPSConsole)this.buffer).WriteLine("PoshConsole 2.1.2011.520");
            }
         }
      }
      ///// <summary>Handles the LocationChanged event of the Window control.</summary>
      ///// <param name="sender">The source of the event.</param>
      ///// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
      //private void OnWindowLocationChanged(object sender, EventArgs e)
      //{
      //   if (WindowState == WindowState.Normal)
      //   {
      //      CornerRadius cornerRadius = _defaultCornerRadius;
      //      if (_defaultCornerRadius == default(CornerRadius))
      //      {
      //         cornerRadius = new CornerRadius(20, 0, 5, 5);
      //      }
      //      Rect workarea = new Rect(SystemParameters.VirtualScreenLeft,
      //                                SystemParameters.VirtualScreenTop,
      //                                SystemParameters.VirtualScreenWidth,
      //                                SystemParameters.VirtualScreenHeight);

      //      if (this.Left == workarea.Left)
      //      {
      //         cornerRadius.BottomLeft = 0.0;
      //         cornerRadius.TopLeft = 0.0;
      //      }
      //      if (this.Top == workarea.Top)
      //      {
      //         cornerRadius.TopLeft = 0.0;
      //         cornerRadius.TopRight = 0.0;
      //      }
      //      if (this.RestoreBounds.Right == workarea.Right)
      //      {
      //         cornerRadius.TopRight = 0.0;
      //         cornerRadius.BottomRight = 0.0;
      //      }
      //      if (this.RestoreBounds.Bottom >= workarea.Bottom)
      //      {
      //         cornerRadius.BottomRight = 0.0;
      //         cornerRadius.BottomLeft = 0.0;
      //      }

      //      foreach (CustomChrome chrome in NativeWpf.SelectBehaviors<CustomChrome>(this))
      //      {
      //         chrome.CornerRadius = cornerRadius;
      //      }
      //   }
      //   else
      //   {
      //      foreach (CustomChrome chrome in NativeWpf.SelectBehaviors<CustomChrome>(this))
      //      {
      //         chrome.CornerRadius = _defaultCornerRadius;
      //      }
      //   }
      //}

      ///// <summary>
      ///// Handles the SizeChanged event of the Window control.
      ///// </summary>
      ///// <param name="sender">The source of the event.</param>
      ///// <param name="e">The <see cref="System.Windows.SizeChangedEventArgs"/> instance containing the event data.</param>
      //private void OnWindowSizeChanged(object sender, SizeChangedEventArgs e)
      //{
      //   // we only reset the saved settings when something other than animation changes the Window size
      //   double h = (double)this.GetAnimationBaseValue(HeightProperty);
      //   if (Properties.Settings.Default.WindowHeight != h)
      //   {
      //      Properties.Settings.Default.WindowHeight = h;
      //      double w = (double)this.GetAnimationBaseValue(WidthProperty);
      //      if(!Double.IsNaN(w)) {
      //         Properties.Settings.Default.WindowWidth = w;
      //      }
      //   }
      //}

      /// <summary>
      /// Handles the SourceInitialized event of the Window control.
      /// </summary>
      /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
      protected override void  OnSourceInitialized(EventArgs e)
      {
         // NOTE: we override OnSourceInitialized so we can control the order
         // this way, the base event (and it's handlers) happen before us
         // and we can handle the unregistered hotkeys (should probably make that an event on the HotkeysBehavior)
         base.OnSourceInitialized(e);

         Cursor = Cursors.AppStarting;
         this.TryExtendFrameIntoClientArea(new Thickness(-1));
         var initWarnings = new StringBuilder();

         // _Hotkeys = NativeWpf.SelectBehaviors<HotkeysBehavior>(this).FirstOrDefault();

         if (_Hotkeys != null)
         {
            int k = -1;
            int count = _Hotkeys.UnregisteredKeys.Count;
            while (++k < count)
            {
               KeyBinding key = _Hotkeys.UnregisteredKeys[k];
               // hypothetically, you would show them a GUI for changing the hotkeys... 

               // but you could try modifying them yourself ...
               ModifierKeys mk = HotkeysBehavior.AddModifier(key.Modifiers);
               if (mk != ModifierKeys.None)
               {
                  initWarnings.AppendFormat("Hotkey taken: {0} + {1} for {2}\nModifying it to {3}, {0} + {1}.\n\n", key.Modifiers, key.Key, key.Command, mk);
                  key.Modifiers |= mk;
                  _Hotkeys.Hotkeys.Add(key);
               }
               else
               {
                  initWarnings.AppendFormat("Can't register hotkey for {2}\nWe tried registering it as {0} + {1}.\n\n", key.Modifiers, key.Key, key.Command);
                  //   // MessageBox.Show(string.Format("Can't register hotkey: {0}+{1} \nfor {2}.", key.Modifiers, key.Key, key.Command, mk));
                  //   //key.Modifiers |= mk;
                  //   //hk.Add(key);
               }
            }
         }
         // LOAD the startup banner only when it's set (instead of removing it after)
         if (Properties.Settings.Default.StartupBanner && System.IO.File.Exists("StartupBanner.xaml"))
         {
            try
            {
               Paragraph banner;
               ErrorRecord error;
               System.IO.FileInfo startup = new System.IO.FileInfo("StartupBanner.xaml");
               if (startup.TryLoadXaml(out banner, out error))
               {
                  // Copy over *all* resources from the DOCUMENT to the BANNER
                  // NOTE: be careful not to put resources in the document you're not willing to expose
                  // NOTE: this will overwrite resources with matching keys, so banner-makers need to be aware
                  foreach (string key in buffer.Document.Resources.Keys)
                  {
                     banner.Resources[key] = buffer.Document.Resources[key];
                  }
                  banner.Padding = new Thickness(5);
                  buffer.Document.Blocks.InsertBefore(buffer.Document.Blocks.FirstBlock, banner);
               }
               else
               {
                  ((IPSConsole)buffer).WriteLine("PoshConsole 1.0.2010.308");
               }

               // Document.Blocks.InsertBefore(Document.Blocks.FirstBlock, new Paragraph(new Run("PoshConsole`nVersion 1.0.2007.8150")));
               // Document.Blocks.AddRange(LoadXamlBlocks("StartupBanner.xaml"));
            }
            catch (Exception ex)
            {
               Trace.TraceError(@"Problem loading StartupBanner.xaml\n{0}", ex.Message);
               buffer.Document.Blocks.Clear();
               ((IPSConsole)buffer).WriteLine("PoshConsole 1.0.2010.308");
            }
         }

         if (initWarnings.Length > 0)
         {
            ((IPSConsole) buffer).WriteWarningLine(initWarnings.ToString());
         }

         // hook mousedown and call DragMove() to make the whole Window a drag handle
         Toolbar.PreviewMouseLeftButtonDown += DragHandler;
         progress.PreviewMouseLeftButtonDown += DragHandler;
         buffer.PreviewMouseLeftButtonDown += DragHandler;
         buffer.Focus();

      }
 private void LoadAurora()
 {
    // LOAD the aurora header only when it's set (instead of removing it after)
    if (Style == Resources["MetroStyle"] && Settings.Default.StartupBanner && System.IO.File.Exists("AuroraHeader.xaml"))
    {
       try
       {
          System.Windows.FrameworkElement header;
          ErrorRecord error;
          var startup = new System.IO.FileInfo("AuroraHeader.xaml");
          if (startup.TryLoadXaml(out header, out error))
          {
             // Copy over *all* resources from the DOCUMENT to the BANNER
             // NOTE: be careful not to put resources in the document you're not willing to expose
             // NOTE: this will overwrite resources with matching keys, so banner-makers need to be aware
             foreach (string key in buffer.Document.Resources.Keys)
             {
                header.Resources[key] = buffer.Document.Resources[key];
             }
             var wrapperGrid = (Grid)Template.FindName("MetroWrapper", this);
             wrapperGrid.Children.Insert(0, header);
          }
          else
          {
             var geometry = new StreamGeometry();
             using (var ctx = geometry.Open())
             {
                ctx.BeginFigure(new Point(-40, -40), true /* is filled */, true /* is closed */);
                ctx.QuadraticBezierTo(new Point(-120, 80), new Point(-20, 80), false, true);
                ctx.QuadraticBezierTo(new Point(-0, 83), new Point(200, 50), false, true);
                ctx.QuadraticBezierTo(new Point(300, 30), new Point(360, 60), false, true);
                ctx.QuadraticBezierTo(new Point(400, 80), new Point(500, 70), false, true);
                ctx.QuadraticBezierTo(new Point(660, 50), new Point(850, 90), false, true);
                ctx.QuadraticBezierTo(new Point(900, 100), new Point(1000, 60), false, true);
                ctx.QuadraticBezierTo(new Point(1100, 20), new Point(1300, 40), false, true);
                ctx.QuadraticBezierTo(new Point(1540, 80), new Point(2000, -40), false, true);
             }
             var brush =
                new LinearGradientBrush(
                   new GradientStopCollection(
                      new[]
                         {
                            new GradientStop(Color.FromArgb(0x39, 0x29, 0x53, 0x8B), 0),
                            new GradientStop(Color.FromArgb(0x94, 0x12, 0xA6, 0xF3), 0.125),
                            new GradientStop(Color.FromArgb(0x8F, 0x18, 0x41, 0xE8), 0.28),
                            new GradientStop(Color.FromArgb(0x66, 0x51, 0x22, 0xD6), 0.431),
                            new GradientStop(Color.FromArgb(0x6C, 0x63, 0x16, 0xD8), 0.56),
                            new GradientStop(Color.FromArgb(0x8F, 0x15, 0x42, 0xCC), 0.659),
                            new GradientStop(Color.FromArgb(0x92, 0x27, 0x83, 0xB4), 0.828),
                            new GradientStop(Color.FromArgb(0x8F, 0x18, 0x9A, 0xFF), 1)
                         }),
                   new Point(0, 0),
                   new Point(1, 1));
             var path = new System.Windows.Shapes.Path
                {
                   Stroke = Brushes.Transparent,
                   StrokeThickness = 0,
                   Effect = new BlurEffect { Radius = 50 },
                   Data = geometry,
                   Fill = brush
                };
             var wrapperGrid = (Grid)Template.FindName("MetroWrapper", this);
             wrapperGrid.Children.Insert(0, path);
          }
       }
       catch (Exception ex)
       {
          Trace.TraceError(@"Problem loading AuroraHeader.xaml\n{0}", ex.Message);
       }
    }
 }