本文整理匯總了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 ();
}
示例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;
}