使用未呈现的控件的可视刷? [英] Visual brush using control which isn't rendered?

查看:136
本文介绍了使用未呈现的控件的可视刷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在玩弄一个想法而且我已经碰到了一堵砖墙。我正在使用一个控制台应用程序在内存中创建一个可视化控件(精确的DevExpress图表控件),然后我尝试使用VisualBrush将该控件保存到图像,但它不起作用,因为(我假设)控件没有被绘制到屏幕上。

I'm playing around with an idea at the moment and I've hit a brick wall. I'm using a console app to create a visual control (DevExpress chartcontrol to be precise) in memory, I'm then trying to save that control to an image using a VisualBrush but it won't work because (I assume) the control isn't drawn to the screen.

我已将代码放在下面,所以你知道我现在在哪里。有谁知道我怎么可能使用控制台应用程序将此控件保存到图像(理想情况下jpg,但任何事情都会...)我真的不想将它渲染到屏幕上,即使是一毫秒就可以保存它......

I've put my code in below so you know where I am at the moment. Does anyone know how I could possibly save this control to an image (ideally jpg, but anything will do...) using a console app? I really don't want to have to render it to the screen even for a millisecond just to be able to save it...

static void sl_CreateDetail(FrameworkElement chartControl1, CreateAreaEventArgs e)
{
        var brush = new VisualBrush(chartControl1);
        var visual = new DrawingVisual();
        DrawingContext context = visual.RenderOpen();

        context.DrawRectangle(brush, null,
            new Rect(0, 0, chartControl1.ActualWidth, chartControl1.ActualHeight));
        context.Close();

        var bmp = new RenderTargetBitmap((int)chartControl1.ActualWidth,
            (int)chartControl1.ActualHeight, 96, 96, PixelFormats.Pbgra32);

        bmp.Render(visual);
        e.Data = bmp;
}


推荐答案

我尝试过Measure(),安排()等,然后发现如果Visual有一个父亲这些DO工作!在我的情况下,我从一个容器中删除Visual,更新其属性(颜色等),然后尝试将其用作VisualBrush并且它没有得到更新。在Measure()和Arrange()的持续时间内将其保留在原始容器中(即使它已在屏幕外完成)。

I tried Measure(), Arrange(), etc, then discovered that these DO work if the Visual has a parent! In my case I was removing the Visual from one container, updating its properties (colour, etc), then trying to use it as a VisualBrush and it wasn't getting updated. Leaving it in the original container for the duration of Measure() and Arrange() fixed it (even though it was all done offscreen).

这篇关于使用未呈现的控件的可视刷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆