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


C# Rectangle.UpdateLayout方法代码示例

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


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

示例1: LayoutUpdatedAndLoaded

		public void LayoutUpdatedAndLoaded ()
		{
			List<string> events = new List<string>();

			EventHandler handler = delegate { events.Add ("LayoutUpdated"); };

			Rectangle r = new Rectangle ();

			r.LayoutUpdated += handler;
			r.Loaded += delegate { events.Add ("Loaded"); };

			TestPanel.Children.Add (r);

			r.UpdateLayout ();
			Assert.AreEqual (1, events.Count, "#1");
			Assert.AreEqual ("LayoutUpdated", events [0], "#2");
			Enqueue (() => {
				Assert.IsTrue (events.Count >= 2, "#3");
				Assert.AreEqual ("Loaded", events [1], "#4");
				r.LayoutUpdated -= handler;
			});
			EnqueueTestComplete ();
		}
开发者ID:dfr0,项目名称:moon,代码行数:23,代码来源:FrameworkElementTest.cs

示例2: InitializeAdornedElementImage

    protected override Rectangle InitializeAdornedElementImage()
    {
      Rect adornedBounds = VisualTreeHelper.GetDescendantBounds( this.AdornedElement );

      // Round the height and width of the bounds to reduce the 
      // blur effect caused by the RenderTargetBitmap. 
      // When drawing Text into RenderTargetBitmap, the ClearType 
      // reverts to grayscale causing a blur effect. If there is 
      // also an extrapolation, the blur effect will be worst.
      int roundedHeight = ( int )Math.Round( adornedBounds.Height, MidpointRounding.ToEven );
      int roundedWidth = ( int )Math.Round( adornedBounds.Width, MidpointRounding.ToEven );

      VisualBrush brush = new VisualBrush( this.AdornedElement );

      Rectangle rectangle = new Rectangle();

      // Only if we have something to adorn
      if( this.DeepCopy
        && ( ( roundedWidth > 0 ) && ( roundedHeight > 0 ) ) )
      {
        try
        {
          RenderTargetBitmap bitmap = new RenderTargetBitmap( roundedWidth,
            roundedHeight,
            96,
            96,
            PixelFormats.Pbgra32 );

          DrawingVisual drawingVisual = new DrawingVisual();

          using( DrawingContext context = drawingVisual.RenderOpen() )
          {
            Rect finalRect = new Rect( 0,
                0,
                roundedWidth,
                roundedHeight );

            context.DrawRectangle( brush, null, finalRect );
          }

          bitmap.Render( drawingVisual );

          // Ensure to set the Height and Width
          // values for the Fill does not resize the 
          // rectangle if it is larger. This also
          // reduce the blur effect.
          rectangle.Height = roundedHeight;
          rectangle.Width = roundedWidth;
          rectangle.UpdateLayout();

          // Adding BitmapScallingMode using any other BitmapScalingMode cause some
          // blur in the resulting Bitmap
          RenderOptions.SetBitmapScalingMode( rectangle, BitmapScalingMode.NearestNeighbor );
          rectangle.Fill = new ImageBrush( bitmap );

          // Translate the Top Left corner of the rectangle that
          // contains the AdornedElement
          if( !adornedBounds.Size.IsEmpty )
          {
            rectangle.RenderTransform = new TranslateTransform( adornedBounds.X, adornedBounds.Y );
          }
        }
        catch( Exception )
        {
          // Avoid any exception and use the brush itself
          rectangle.Fill = brush;
        }
      }
      else
      {
        rectangle.Fill = brush;
      }

      return rectangle;
    }
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:75,代码来源:AnimatedDraggedElementAdorner.cs


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