移除的视觉效果显示在实时视觉树中

问题描述

在这些行上有一些代码

void init() {
    UIElement = new UserControl();
    auto hostVisual = Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(UIElement);
    auto compositor = hostVisual->Compositor;
    auto visualRoot = compositor->CreateContainerVisual();
    Windows::UI::Xaml::Hosting::ElementCompositionPreview::SetElementChildVisual(UIElement,container);
}

void update() {
    auto hostVisual = Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(UIElement);
    auto visualTreeRoot = dynamic_cast<Windows::UI::Composition::ContainerVisual ^>
        (Windows::UI::Xaml::Hosting::ElementCompositionPreview::GetElementChildVisual(view().nativeView()));
    visualTreeRoot->Children->RemoveAll();
    auto spriteVisual1 = visualTreeRoot ->Compositor->CreateSpriteVisual();
    : //Set properties like size,color of the SpriteVisual
    : 
    visualTreeRoot->Children->InsertAtTop(spriteVisual1);
    :
    :
    visualTreeRoot->Children->InsertAtTop(spriteVisual2);
}

现在我对代码的期望是每次更新时,都应该删除ContainerVisual 中的所有子项,并且每次都添加新的子项。但实时可视化树(在 Debug->Window->Live Visual Tree 下)显示内容与此不同

enter image description here

奇怪的部分是,其中只有两个实际上在 Live Property Explorer as 中显示了有效属性

Property Explorer Valid

而其他的只是显示为空

Property Explorer InValid

这是我的代码或 VS 中的一个错误,它没有从树中删除删除视觉效果吗?如果没有,我还需要做什么?

附言有趣的是,在 Close()调用 Visual 会引发编译错误,尽管它在 document!我曾使用 Close() API 怀疑我以某种方式泄漏了资源。这是错误

错误 C2039:“关闭”:不是 'Windows::UI::Composition::Visual'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)