当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.FileInfo.TryLoadXaml方法代码示例

本文整理汇总了C#中System.IO.FileInfo.TryLoadXaml方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.TryLoadXaml方法的具体用法?C# System.IO.FileInfo.TryLoadXaml怎么用?C# System.IO.FileInfo.TryLoadXaml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了System.IO.FileInfo.TryLoadXaml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadBanner

      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");
            }
         }
      }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:38,代码来源:PoshConsole.xaml.cs

示例2: OnSourceInitialized


//.........这里部分代码省略.........
      //   {
      //      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();

      }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:101,代码来源:NativeChromePoshConsole.xaml.cs

示例3: LoadAurora

 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);
       }
    }
 }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:71,代码来源:PoshConsole.xaml.cs


注:本文中的System.IO.FileInfo.TryLoadXaml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。