[UWP]奇怪的画布控制行为 [英] [UWP] Odd Canvas control behavior

查看:60
本文介绍了[UWP]奇怪的画布控制行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的应用程序允许用户在Canvas控件上放置自定义控件。可以调整,移动和自定义这些自定义控件,以满足其在整个应用程序中的用途。 程序可以在
画布上保存控件的布局,以便在应用程序再次启动时加载。

The application I'm working allows users to place custom controls on a Canvas control. These custom controls can be sized, moved and customized to suite their purpose in the overall application.  The program can save the layout of the controls on the canvas for loading when the application starts again.

当应用程序启动时,它会检查是否有任何已保存的控件设置如果找到它们将加载它们。然后,应用程序将读取设置,从设置中创建自定义控件并将其放置在应用程序的"画布"上。该应用程序是
执行此控件布局以响应Canvas的已加载事件。在app启动时创建和放置控件的方式与在应用程序启动并运行时用户在Canvas上放置自定义控件的方式相同:
控件已创建,它将添加到Canvas .Children集合以及为控件设置的Canvas.Left和Canvas.Top属性。

When the application starts it checks to see if there are any saved control settings and will load them if they are found. The app then reads the settings, creates the custom controls from the settings and places them on the Canvas of the app. The app is doing this layout of controls in response to the Loaded event of the Canvas. The creation and placement of the controls at app startup is done in the same manner as when a user places a custom control on the Canvas when the app is up and running: The control is created, it is added to the Canvas.Children collection and the Canvas.Left and Canvas.Top properties are set for the control.

问题是当我在app启动时创建和放置控件时,控件是在画布上看不到。它们位于Canvas.Children集合中,但它们的UI未显示。

The problem is that when I'm creating and placing the controls at app startup, the controls are not visible on the Canvas. They are in the Canvas.Children collection but their UI is not being displayed.

通过在加载设置和创建控件时添加几秒延迟,我可以获得自定义控件以在Canvas上显示其UI。这看起来很奇怪。我想在等待Canvas.Loaded事件之后,托管控件的canvas
就可以准备好了。我真的不愿意在应用程序启动时添加一些任意延迟。我需要一些方法来确定Canvas控件何时准备好包含和显示子控件。

By adding a few second delay to the loading of the settings and creation of the controls, I can get the custom controls to show their UI on the Canvas. This seems really strange. I would think that after waiting for the Canvas.Loaded event that the canvas that hosts the controls would be ready for action. I'm really reluctant to add some arbitrary delay in the startup of the app. I need some way of determining precisely when a Canvas control is ready to contain and display child controls.

推荐答案

嗨Jim Yong,

Hi Jim Yong,

这真是一种奇怪的行为,你能提供一个简单的最小样本代码来帮助我重现它吗?如果有一个复制项目,对我们进行调查会很有帮助。

It is really a strange behavior, could you provide a simple minimal sample code to help me reproduce it? It will be helpful for us to investigate it if there is a reproducing project.

祝你好运,

Breeze


这篇关于[UWP]奇怪的画布控制行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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