从UserControl获取图像(预览) [英] Getting Image (Preview) from UserControl
问题描述
大家好.
好吧,这是一个奇怪的问题,但是来了
是否可以在不以用户控件的形式呈现并将其加载到wpf表单的情况下表示有关usercontrol的预览?
用类似这样的代码
在xaml中,我们有预览图像组件
Hi all.
Well this is odd question but here it comes
Is it possible to represent preview about usercontrol without presenting and loaded it on the wpf form as a usercontrol?
in code something like this
in xaml we have preview image component
<Image x:Name="previewImage"></Image>
并在代码背后的某个地方
and somewhere in codebehind
MyUserControl control = new MyUserControl();
//get here image of control and present it as a Source of previewImage component
previewImage.Source = "Here is preview about my usercontrol"
接收到的图像应在运行时内存中处理,而不要保存在硬盘驱动器中.
希望你有主意:)
干杯!
Received image should be handled in runtime memory and not to be saved in hard drive.
Hope you got idea :)
Cheers!
推荐答案
您可以使用您可以添加一个
Rectangle
(而不是您的Image
):You can add a
Rectangle
(instead of yourImage
):
<Rectangle Name="myRect" Stroke="Black" StrokeThickness="2" Margin="5" />
,并使用包含您的控件的
VisualBrush
设置其Fill
:and, set its
Fill
with aVisualBrush
that contains your control:MyUserControl control = new MyUserControl(); VisualBrush vb = new VisualBrush { Visual = control, Stretch = System.Windows.Media.Stretch.Uniform }; myRect.Fill = vb;
这篇关于从UserControl获取图像(预览)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!