uwp - 从 UIElement 中提取 ContainerVisual
问题描述
ElementCompositionPreview类允许通过GetElementVisual API从UIElement中提取支持的Visual 。有没有办法从ContainerVisual中提取?由于 a只是所有类型s 的基类,有没有办法确定提取的这个是什么类型的?我尝试诉诸于,但这会在尝试将其转换为. 这是否表明这只是一个普通的类实例,不能用作其他任何东西,并且仅限于接口使用?UIElement
Visual
Visual
Visual
Visual
dynamic_cast
nullptr
ContainerVisual
Visual
Visual
编辑:
为我的处理方式添加更多背景信息。这是我的代码中的内容
FrameworkElement^ elem = new UserControl();
auto visual = ElementCompositionPreview::GetElementVisual(elem);
if(auto container = dynamic_cast<ContainerVisual^>(visual)) {
//Use ContainerVisual APIs and use it's children property to insert visuals in the visual tree
}
解决方案
您可以ContainerVisual
从Compositor
从UIElement
.
请检查以下代码:
FrameworkElement^ elem =ref new UserControl();
auto _compositor = ElementCompositionPreview::GetElementVisual(elem)->Compositor;
auto containerVisual= _compositor->CreateContainerVisual();
if (containerVisual)
{
//Test if the containerVisual is a null value
containerVisual->Comment = "1122";
}
auto str = containerVisual->Comment;
推荐阅读
- java - 在 AppCompactActivity 中设置布局元素分为片段
- regex - 为什么这个正则表达式不适用于 Analytics?
- mysql - 也许如何从选择中选择
- c# - C#串行数据被分成随机数量,试图找到回车没有运气
- docker - 无法通过覆盖网络跨 2 个节点正确通信
- mysql - 如何在 MySQL 中查询此 JSON 有效负载?
- homebrew - 将 OpenCV 与 DarkNet 一起使用时出错 - 为自己的数据集生成锚点
- omnet++ - OMNET++:如何创建每秒触发的计时器事件?
- sql-server - SQL Server 时态表不保留删除历史记录以在事务中进行更新和删除
- excel - Excel-vba将不同的工作表保存到不同文件夹中的PDF