我有一個包含Winform和WPF元素集合的WPF面板(在WPF應用程序中)。 Winform元素通過WindowsFormsHost
託管。使用Winform和WPF元素從面板創建BitmapSource
我需要創建整個面板的BitmapSource(就像它一樣),所以我可以操作它/保存/打印出來。
創建WPF元素的BitmapSource不是問題,但Winform元素沒有呈現(它們應該是隻有一個空白空間)。那
一個例子:
void GetBitmapSource(FrameworkElement element)
{
var matrix = PresentationSource.FromVisual(element).CompositionTarget.TransformToDevice;
double dpiX = 96.0 * matrix.M11;
double dpiY = 96.0 * matrix.M22;
var bitmapSource = new RenderTargetBitmap((int)element.ActualWidth + 1, (int)element.ActualHeight + 1, dpiX, dpiY, PixelFormats.Pbgra32);
bitmapSource.Render(element);
return bitmapSource;
}
這將打印WPF元素就好了,但忽略Winform的內容。我如何包含它?
下圖顯示了左側的Tabpanel和右側的BitmapSource。注意Winform矩形的內容是空的。
也許有所幫助:http://stackoverflow.com/q/1756954/1136211 – Clemens
我發現從托馬斯Levesque的一種解決方案,他的回答[這裏](http://stackoverflow.com/a/1756976/3064934 )。 – Daltons