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


C# UIElement.Measure方法代码示例

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


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

示例1: CreateElementScreenshot

		private static BitmapSource CreateElementScreenshot(UIElement uiElement)
		{
			bool measureValid = uiElement.IsMeasureValid;

			if (!measureValid)
			{
				double width = 300;
				double height = 300;

				FrameworkElement frElement = uiElement as FrameworkElement;
				if (frElement != null)
				{
					if (!Double.IsNaN(frElement.Width))
						width = frElement.Width;
					if (!Double.IsNaN(frElement.Height))
						height = frElement.Height;
				}

				Size size = new Size(width, height);
				uiElement.Measure(size);
				uiElement.Arrange(new Rect(size));
			}

			RenderTargetBitmap bmp = new RenderTargetBitmap(
				(int)uiElement.RenderSize.Width, (int)uiElement.RenderSize.Height,
				96, 96, PixelFormats.Default);

			// this is waiting for dispatcher to perform measure, arrange and render passes
			uiElement.Dispatcher.Invoke(((Action)(() => { })), DispatcherPriority.Background);

			bmp.Render(uiElement);

			return bmp;
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:34,代码来源:ScreenshotHelper.cs

示例2: CreateCursor

    public static Cursor CreateCursor(UIElement element, int xHotSpot, 
        int yHotSpot)
    {
      element.Measure(new Size(double.PositiveInfinity, 
        double.PositiveInfinity));
      element.Arrange(new Rect(0, 0, element.DesiredSize.Width, 
        element.DesiredSize.Height));

      RenderTargetBitmap rtb = 
        new RenderTargetBitmap((int)element.DesiredSize.Width, 
          (int)element.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
      rtb.Render(element);

      PngBitmapEncoder encoder = new PngBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(rtb));

      MemoryStream ms = new MemoryStream();
      encoder.Save(ms);

      System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);

      ms.Close();
      ms.Dispose();     

      Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);

      bmp.Dispose();

      return cur;
    }
开发者ID:heinzsack,项目名称:DEV,代码行数:30,代码来源:CursorHelper.cs

示例3: ToImageSource

        public static ImageSource ToImageSource(UIElement element, System.Windows.Size size)
        {
            element.Measure(size);
            element.Arrange(new Rect(size));

            var bmp = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(element);
            return bmp;
        }
开发者ID:node-net,项目名称:Node.Net,代码行数:9,代码来源:UIElement.Extensions.cs

示例4: SaveElement

 public static bool SaveElement(UIElement element, Tile tile)
 {
     try
     {
         var side = (tile == Tile.Small) ? 159 : 336;
         element.Measure(new Size(side, side));
         element.Arrange(new Rect(0, 0, side, side));
         var bmp = new WriteableBitmap(side, side);
         bmp.Render(element, null);
         bmp.Invalidate();
         var name = tile.ToString() + Guid.NewGuid() + ".png";
         using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
         {
             if (!isf.DirectoryExists("/CustomLiveTiles"))
             {
                 isf.CreateDirectory("/CustomLiveTiles");
             }
             using (var myFileStream = isf.CreateFile("shared/shellcontent/" + name))
             {
                 // Encode WriteableBitmap object to a PNG stream.
                 bmp.WritePng(myFileStream);
             }
             var filesTodelete =
                      from f in isf.GetFileNames("shared/shellcontent/" + tile + "*").AsQueryable()
                      where !f.EndsWith(name)
                      select f;
             foreach (var file in filesTodelete)
             {
                 isf.DeleteFile("shared/shellcontent/" + file);
             }
         }
         SaveTilePart("isostore:/Shared/ShellContent/" + name, tile);
     }
     catch (Exception)
     {
         Thread.Sleep(1000);
         if (tile == Tile.Small)
         {
             SaveTilePart(GetDefaultSmallTile(), tile);
         }
         else
         {
             SaveTilePart((tile == Tile.Front) ? GetDefaultFrontTile() : GetDefaultBackTile(), tile);
         }
         return false;
     }
     return true;
 }
开发者ID:JanJoris,项目名称:VikingApp,代码行数:48,代码来源:Helper.cs

示例5: GenerateBitmapSource

        public static BitmapSource GenerateBitmapSource(UIElement element, double renderWidth, double renderHeight, bool performLayout)
        {
            if (performLayout)
            {
                element.Measure(new Size(renderWidth, renderHeight));
                element.Arrange(new Rect(new Size(renderWidth, renderHeight)));
            }

            var bmp = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, 96, 96, PixelFormats.Pbgra32);
            var dv = new DrawingVisual();
            using (DrawingContext dc = dv.RenderOpen())
            {
                dc.DrawRectangle(new VisualBrush(element), null, new Rect(0, 0, renderWidth, renderHeight));
            }
            bmp.Render(dv);
            return bmp;
        }
开发者ID:MahApps,项目名称:MahApps.Metro,代码行数:17,代码来源:Utilities.Wpf.cs

示例6: RenderControlToBitmap

        private static void RenderControlToBitmap(UIElement control, [NotNull] string path, int scale = 1,
            double maxWidth = double.PositiveInfinity, double maxheight = double.PositiveInfinity)
        {
            var availableSize = new Size(maxWidth, maxheight);
            control.Measure(availableSize);
            var desiredSize = control.DesiredSize;
            control.Arrange(new Rect(desiredSize));
            var dpi = scale * 96;
            var bmp = new RenderTargetBitmap((int)desiredSize.Width * scale, (int)desiredSize.Height * scale, dpi, dpi, PixelFormats.Pbgra32);

            bmp.Render(control);

            var encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bmp));
            var dir = Path.GetDirectoryName(path);
            if (dir == null)
                throw new InvalidPathException(path);
            Directory.CreateDirectory(dir);
            using (Stream stm = File.Create(path))
                encoder.Save(stm);
        }
开发者ID:davidkron,项目名称:DevArch,代码行数:22,代码来源:BitmapRenderer.cs

示例7: GetElementPixelSize

        public System.Windows.Size GetElementPixelSize(UIElement element)
        {
            Matrix transformToDevice;
            var source = PresentationSource.FromVisual(element);
            if (source != null)
            {
                transformToDevice = source.CompositionTarget.TransformToDevice;
            }
            else
            {
                using (var newSource = new HwndSource(new HwndSourceParameters()))
                {
                    transformToDevice = newSource.CompositionTarget.TransformToDevice;
                }
            }

            if (element.DesiredSize == new System.Windows.Size())
            {
                element.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            }

            return (System.Windows.Size)transformToDevice.Transform((Vector)element.DesiredSize);
        }
开发者ID:onetruejones,项目名称:FractalApplication,代码行数:23,代码来源:MainWindow.xaml.cs

示例8: ToImage

        private async Task ToImage(UIElement element, double width, double height)
        {
            element.Measure(new Size(width, height));
            element.Arrange(new Rect { Height = height, Width = width });
            element.UpdateLayout();

            var bitmap = new WriteableBitmap((int)width, (int)height);
            bitmap.Render(element, null);
            bitmap.Invalidate();

            await SaveTheImage(bitmap, WideTileUrl);
        }
开发者ID:Austin503,项目名称:Emby.WindowsPhone,代码行数:12,代码来源:TileService.cs

示例9: ToImage

        private async Task ToImage(UIElement element)
        {
            element.Measure(new Size(480, 800));
            element.Arrange(new Rect{ Height = 800, Width = 480});
            element.UpdateLayout();

            var bitmap = new WriteableBitmap(480, 800);
            bitmap.Render(element, null);
            bitmap.Invalidate();

            await SaveTheImage(bitmap);
        }
开发者ID:gep13,项目名称:Emby.WindowsPhone,代码行数:12,代码来源:LockScreenService.cs

示例10: DoLayout

        /// <summary>
        /// We initiate the layout on the tree rooted at the Visual to which VisualBrush points.
        /// </summary>
        private void DoLayout(UIElement element)
        {
            Debug.Assert(element != null);

            DependencyObject parent = VisualTreeHelper.GetParent(element);
            if (!(element.IsRootElement)
                && (parent == null || parent is Visual3D))
            {
                //
                // PropagateResumeLayout sets the LayoutSuspended flag to false if it were true.
                //
                UIElement.PropagateResumeLayout(null, element);
                element.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                element.Arrange(new Rect(element.DesiredSize));
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:19,代码来源:VisualBrush.cs

示例11: CreateCursor

        public static Cursor CreateCursor(UIElement element, int xHotSpot, int yHotSpot,bool isTransparent)
        {
            try
            {
                element.Measure(new Size(double.PositiveInfinity,
                                double.PositiveInfinity));
                element.Arrange(new Rect(0, 0, element.DesiredSize.Width,
                  element.DesiredSize.Height));

                RenderTargetBitmap rtb =
                  new RenderTargetBitmap((int)element.DesiredSize.Width,
                    (int)element.DesiredSize.Height, 96, 96,
                    PixelFormats.Pbgra32);
                rtb.Render(element);

                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(rtb));

                MemoryStream ms = new MemoryStream();
                encoder.Save(ms);

                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);



                if (isTransparent)
                {

                    System.Drawing.Color backColor = bmp.GetPixel(1, 1);
                    bmp.MakeTransparent(backColor);
                }



                Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);

                ms.Close();
                ms.Dispose();


                //VictorDEBUG
                bmp.Dispose();

                return cur;
            }
            catch
            {
            }
            return null;

        }
开发者ID:ohadmanor,项目名称:TDS,代码行数:51,代码来源:CursorHelper.cs

示例12: MeasureDecoratorChild

		public static Size MeasureDecoratorChild (UIElement child, Size constraint, double borderThickness)
		{
			if (child == null)
				return Size.Empty;
			child.Measure (GetMeasureSizeToPassToDecoratorChild (constraint, borderThickness));
			return GetDesiredDecoratorSize (child.DesiredSize, borderThickness);
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:7,代码来源:Utility.cs


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