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


C# FrameworkElement.Arrange方法代码示例

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


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

示例1: GetPngImage

 private static byte[] GetPngImage(FrameworkElement element)
 {
     var size = new Size(double.PositiveInfinity, double.PositiveInfinity);
     element.Measure(size);
     element.Arrange(new Rect(element.DesiredSize));
     var renderTarget =
       new RenderTargetBitmap((int)element.RenderSize.Width,
                              (int)element.RenderSize.Height,
                              96, 96,
                              PixelFormats.Pbgra32);
     var sourceBrush = new VisualBrush(element);
     var drawingVisual = new DrawingVisual();
     using (DrawingContext drawingContext = drawingVisual.RenderOpen())
     {
         drawingContext.DrawRectangle(
             sourceBrush, null, new Rect(
                                    new Point(0, 0),
                                    new Point(element.RenderSize.Width,
                                    element.RenderSize.Height)));
     }
     renderTarget.Render(drawingVisual);
     var pngEncoder = new PngBitmapEncoder();
     pngEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
     using (var outputStream = new MemoryStream())
     {
         pngEncoder.Save(outputStream);
         return outputStream.ToArray();
     }
 }
开发者ID:jwynia,项目名称:ImageGenerator,代码行数:29,代码来源:ImageGenerator.cs

示例2: RealizeFrameworkElement

		public static void RealizeFrameworkElement(FrameworkElement fe) {
			var size = new Size(double.MaxValue, double.MaxValue);
			if (fe.Width > 0 && fe.Height > 0) size = new Size(fe.Width, fe.Height);
			fe.Measure(size);
			fe.Arrange(new Rect(new Point(), fe.DesiredSize));
			fe.UpdateLayout();
		}
开发者ID:goutkannan,项目名称:ironlab,代码行数:7,代码来源:XamlToys.cs

示例3: ArrangeCanvasElements

        /// <summary>
        /// Calls the Arrange function on child canvas elements
        /// </summary>
        /// <param name="xamlObject">The xaml object.</param>
        private static void ArrangeCanvasElements(FrameworkElement xamlObject)
        {
            if (xamlObject is Canvas)
                xamlObject.Arrange(new Rect());

            LogicalTreeHelper
                .GetChildren(xamlObject)
                .Cast<FrameworkElement>()
                .ForEach(ArrangeCanvasElements);
        }
开发者ID:ernstnaezer,项目名称:Manssiere,代码行数:14,代码来源:XamlLoader.cs

示例4: DoWithElementAtSize

        private void DoWithElementAtSize(FrameworkElement element, Size size, Action action)
        {
            Transform transform = element.LayoutTransform;
            element.LayoutTransform = null;

            element.Measure(size);
            element.Arrange(new Rect(size));

            action();

            element.LayoutTransform = transform;
        }
开发者ID:Jamedjo,项目名称:RSTabExplorer,代码行数:12,代码来源:ExportImageService.cs

示例5: InvalidatePosition

		protected virtual void InvalidatePosition(FrameworkElement child)
		{
			if (viewport == null) return;

			var transform = GetTransform(availableSize);

			Size elementSize = GetElementSize(child, AvailableSize, transform);
			child.Measure(elementSize);

			Rect bounds = GetElementScreenBounds(transform, child);
			if (!bounds.IsNaN())
			{
				child.Arrange(bounds);
			}
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:15,代码来源:ViewportPanel.cs

示例6: ToImageSource

        public static ImageSource ToImageSource(FrameworkElement obj)
        {
            Transform transform = obj.LayoutTransform;
            Thickness margin = obj.Margin;
            obj.Margin = new Thickness(0, 0, margin.Right - margin.Left, margin.Bottom - margin.Top);
            Size size = new Size(obj.ActualWidth, obj.ActualHeight);
            obj.Measure(size);
            obj.Arrange(new Rect(size));
            RenderTargetBitmap bmp = new RenderTargetBitmap((int)obj.ActualWidth, (int)obj.ActualHeight, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(obj);
            obj.LayoutTransform = transform;
            obj.Margin = margin;
            return bmp;
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:15,代码来源:Common.cs

示例7: WpfVisual

        public WpfVisual(FrameworkElement element, int defaultWidth = BadgeCaps.Width, int defaultHeight = BadgeCaps.Height, bool dither = false, bool enableBlend = false)
        {
            Element = element;
            Element.Measure(new Size(defaultWidth, defaultHeight));
            Element.Arrange(new Rect(0, 0, defaultWidth, defaultHeight));

            ClipWidth = (int)Math.Ceiling(Element.ActualWidth);
            ClipHeight = (int)Math.Ceiling(Element.ActualHeight);

            Dither = dither;
            EnableBlend = enableBlend;

            m_cachedIntermediate = new BadgeRenderTarget(ClipWidth, ClipHeight);
            m_renderTarget = new RenderTargetBitmap(ClipWidth, ClipHeight, 96, 96, PixelFormats.Pbgra32);

            Update(0); // To avoid remeasuring on a background thread
            UpdateCachedImage();
        }
开发者ID:Effix,项目名称:LedBadge,代码行数:18,代码来源:WpfVisual.cs

示例8: XAMLToBitmap

        public static void XAMLToBitmap(FrameworkElement element, string fileName)
        {
            try
            {
                element.RenderTransform = new ScaleTransform(0.1, 0.1);

                element.Measure(new Size((int)element.Width, (int)element.Height));
                element.Arrange(new Rect(new Size((int)element.Width, (int)element.Height)));

                var renderTargetBitmap = new RenderTargetBitmap((int)element.ActualWidth / 10, (int)element.ActualHeight / 10, 96d, 96d, PixelFormats.Pbgra32);
                renderTargetBitmap.Render(element);

                using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
                {
                    var bmpBitmapEncoder = new BmpBitmapEncoder();
                    bmpBitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
                    bmpBitmapEncoder.Save(fileStream);
                }
            }
            catch { }
        }
开发者ID:hjlfmy,项目名称:Rubezh,代码行数:21,代码来源:ImageHelper.cs

示例9: BeginGrandchildAnimation

 internal void BeginGrandchildAnimation( FrameworkElement grandchild, Rect currentRect, Rect placementRect )
 {
     bool isDone = true;
       object placementArgs;
       ChildState state = new ChildState( currentRect );
       AnimationPanel.SetChildState( grandchild, state );
       state.Type = AnimationType.Switch;
       state.BeginTimeStamp = DateTime.Now;
       state.TargetPlacement = placementRect;
       state.Animator = this.GetEffectiveAnimator( AnimationType.Template );
       if( state.Animator != null && !state.TargetPlacement.IsEmpty )
       {
     AnimationRate rate = this.GetEffectiveAnimationRate( AnimationType.Template );
     state.CurrentPlacement = state.Animator.GetInitialChildPlacement( grandchild, state.CurrentPlacement, state.TargetPlacement, this, ref rate, out placementArgs, out isDone );
     state.AnimationRate = rate;
     state.PlacementArgs = placementArgs;
       }
       state.IsAnimating = !isDone;
       grandchild.Arrange( state.IsAnimating ? state.CurrentPlacement : state.TargetPlacement );
       if( state.IsAnimating )
       {
     _animatingGrandchildren.Add( grandchild );
     this.AnimatingChildCount++;
       }
       else
       {
     state.CurrentPlacement = state.TargetPlacement;
       }
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:29,代码来源:AnimationPanel.cs

示例10: InvalidatePosition

		protected override void InvalidatePosition(FrameworkElement child)
		{
			invalidatePositionCalls++;

			if (viewport == null) return;
			if (child.Visibility != Visibility.Visible)
				return;

			var transform = viewport.Transform;

			Size elementSize = GetElementSize(child, AvailableSize, transform);
			child.Measure(elementSize);

			Rect bounds = GetElementScreenBounds(transform, child);
			child.Arrange(bounds);

			var viewportBounds = Viewport2D.GetContentBounds(this);
			if (!viewportBounds.IsEmpty)
				overallViewportBounds = viewportBounds;

			UniteWithBounds(transform, bounds);

			if (!InBatchAdd)
			{
				Viewport2D.SetContentBounds(this, overallViewportBounds);
				ContentBoundsChanged.Raise(this);
			}
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:28,代码来源:ViewportHostPanel.cs

示例11: GenerateImage

        public static BitmapImage GenerateImage(FrameworkElement pFE, int pWidth, int pHeight)
        {;
            pFE.Width = pWidth;
            pFE.Height = pHeight;
            System.Windows.Size theTargetSize = new System.Windows.Size(pWidth, pHeight);
            pFE.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            pFE.Arrange(new Rect(theTargetSize));
            // to affect the changes in the UI, you must call this method at the end to apply the new changes

            pFE.UpdateLayout();
            pFE.InvalidateMeasure();
            pFE.InvalidateArrange();
            pFE.InvalidateVisual();
            var imgEncoder = new PngBitmapEncoder();
            imgEncoder.Interlace = PngInterlaceOption.Off;
            RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)pWidth, (int)pHeight, 96, 96, PixelFormats.Pbgra32);
            bmpSource.Render(pFE);
            imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
            BitmapImage result = new BitmapImage();
            using (var stream = new MemoryStream())
            {
                imgEncoder.Save(stream);
                stream.Seek(0, SeekOrigin.Begin);

                
                
                result.BeginInit();
                // According to MSDN, "The default OnDemand cache option retains access to the stream until the image is needed."
                // Force the bitmap to load right now so we can dispose the stream.
                result.CacheOption = BitmapCacheOption.OnLoad;
                result.StreamSource = stream;
                result.EndInit();
              //  result.Freeze();
                
            }

            return result;


        }
开发者ID:TNOCS,项目名称:csTouch,代码行数:40,代码来源:MgrsEsriLayer.cs

示例12: AddVisualToCanvas

        public void AddVisualToCanvas(FrameworkElement visual, Body body)
        {
            if (body != null)
            {
                new BodyVisualHelper(visual, body);
            }

            //hasn't been rendered yet, so needs to work out it's size
            if (visual.ActualWidth == 0 && visual.ActualHeight == 0)
            {
                Debug.Assert(ActualWidth != 0 && ActualHeight != 0);
                visual.Arrange(new Rect(0, 0, ActualWidth, ActualHeight));
            }

            Children.Add(visual);

            visual.IsHitTestVisible = true;
        }
开发者ID:rbrother,项目名称:seikkailulaakso,代码行数:18,代码来源:Demo.cs

示例13: RenderControl

        /// <summary>
        /// This tells a visual to render itself to a wpf bitmap.  From there, you can get the bytes (colors), or run it through a converter
        /// to save as jpg, bmp files.
        /// </summary>
        /// <remarks>
        /// This fixes an issue where the rendered image is blank:
        /// http://blogs.msdn.com/b/jaimer/archive/2009/07/03/rendertargetbitmap-tips.aspx
        /// </remarks>
        public static BitmapSource RenderControl(FrameworkElement visual, int width, int height, bool isInVisualTree)
        {
            if (!isInVisualTree)
            {
                // If the visual isn't part of the visual tree, then it needs to be forced to finish its layout
                visual.Width = width;
                visual.Height = height;
                visual.Measure(new Size(width, height));        //  I thought these two statements would be expensive, but profiling shows it's mostly all on Render
                visual.Arrange(new Rect(0, 0, width, height));
            }

            RenderTargetBitmap retVal = new RenderTargetBitmap(width, height, DPI, DPI, PixelFormats.Pbgra32);

            DrawingVisual dv = new DrawingVisual();
            using (DrawingContext ctx = dv.RenderOpen())
            {
                VisualBrush vb = new VisualBrush(visual);
                ctx.DrawRectangle(vb, null, new Rect(new Point(0, 0), new Point(width, height)));
            }

            retVal.Render(dv);      //  profiling shows this is the biggest hit

            return retVal;
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:32,代码来源:UtilityWPF.cs

示例14: RecalculateSize

 /// <summary>
 /// Recalculate the size of a FrameworkElement
 /// </summary>
 /// <param name="element">The FrameworkElement to recalculate the size for</param>
 public static void RecalculateSize(FrameworkElement element)
 {
     element.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
     element.Arrange(new Rect(element.DesiredSize));
 }
开发者ID:NathanMagnus,项目名称:NETScoreTranscription,代码行数:9,代码来源:WPFRendering.cs

示例15: PrepareForExport

 private static void PrepareForExport(FrameworkElement element)
 {
     if (element.ActualWidth == 0 && element.ActualHeight == 0)
     {
         double width = element.Width > 0 ? element.Width : 500;
         double height = element.Height > 0 ? element.Height : 300;
         element.Measure(Size.Empty);
         element.Measure(new Size(width, height));
         element.Arrange(new Rect(0, 0, width, height));
         element.UpdateLayout();
     }
 }
开发者ID:Motaz-Al-Zoubi,项目名称:xaml-sdk,代码行数:12,代码来源:Example.xaml.cs


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