本文整理匯總了C#中System.Windows.Controls.UserControl.Measure方法的典型用法代碼示例。如果您正苦於以下問題:C# UserControl.Measure方法的具體用法?C# UserControl.Measure怎麽用?C# UserControl.Measure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Controls.UserControl
的用法示例。
在下文中一共展示了UserControl.Measure方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RenderToFile
public void RenderToFile(UserControl target, [CallerMemberName] string testName = "")
{
string path = Path.Combine(testDirectory, testName + ".wpf.out.png");
RenderTargetBitmap bitmap = new RenderTargetBitmap(
(int)target.Width,
(int)target.Height,
96,
96,
PixelFormats.Pbgra32);
Size size = new Size(target.Width, target.Height);
target.Measure(size);
target.Arrange(new Rect(size));
bitmap.Render(target);
File.Delete(path);
using (FileStream fs = new FileStream(path, FileMode.Create))
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.Save(fs);
}
}
示例2: Initialize
public static void Initialize(this UIElement element)
{
var userControl = new UserControl { Content = element };
userControl.BeginInit(); // hacking different things here
userControl.Measure(new Size(100, 100));
userControl.Arrange(new Rect(new Size(100, 100)));
element.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));
}
示例3: Export
void Export(UserControl tile, int width, int height, string filename)
{
tile.Measure(new Size(width, height));
tile.Arrange(new Rect(0, 0, width, height));
var bmp = new WriteableBitmap(width, height);
bmp.Render(tile, null);
bmp.Invalidate();
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = store.OpenFile(filename, System.IO.FileMode.OpenOrCreate))
{
bmp.SaveJpeg(stream, width, height, 0, 100);
}
}
示例4: PrintReceipt
public void PrintReceipt(UserControl uc)
{
var dialog = new PrintDialog();
var printer = new PrintServer().GetPrintQueues()
.FirstOrDefault(x => x.Name == _printerName);
if (printer != null)
dialog.PrintQueue = printer;
uc.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
uc.Arrange(new Rect(new Point(0, 0), uc.DesiredSize));
dialog.PrintVisual(uc, "receipt");
}