简体   繁体   English

创建用于动态创建用户控件的图像

[英]Creating an image for dynamically creted user control

I am trying to create an image of a user control. 我正在尝试创建用户控件的图像。 The usercontrol is created dynamically. 用户控件是动态创建的。

MyViewsUserControl myViewsCanvas = new MyViewsUserControl(MyViewsViewModel, item.Id);

The usercontrols have a grid and in some cases a chart.I am creating the image using 'RenderTargetBitmap' class. 用户控件有一个网格,在某些情况下还有一个图表。我正在使用'RenderTargetBitmap'类创建图像。 But for some reason the image for grid and chart are not being created. 但是由于某种原因,未创建用于网格和图表的图像。 Can anyone tell me what the problem is? 谁能告诉我问题出在哪里? Is this because the user control is not loaded yet? 这是因为尚未加载用户控件吗?

Note:I am creating the image before loading the user control. 注意:我在加载用户控件之前创建图像。

here is the code for this: 这是代码:

 MyViews.MyViewsUserControl myViewsCanvas = new MyViews.MyViewsUserControl(AllFoundationMyViewsViewModel, item.Id);
 myViewsCanvas.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
 myViewsCanvas.Arrange(new Rect(new Point(), myViewsCanvas.DesiredSize));
 myViewsCanvas.UpdateLayout();
 screenInfo _screenInfo = new screenInfo(item.Id, item.MonarchMenuItem, "MyViews");
 UpdateControls(_DashBoardUserControl, i, myViewsCanvas, _screenInfo, item.MonarchMenuItem.DisplayName);

I am creting the image in updateControls() method. 我在updateControls()方法中创建图像。

在尝试将控件呈现到位图中之前,请不要忘记调用用户控件的Measure,Arrange和UpdateLayout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM