加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 以编程方式从Windows Metro中的网格中删除对象

发布时间:2020-12-16 07:05:43 所属栏目:百科 来源:网络整理
导读:我有几个图像在Grid容器内动画,我需要在动画结束后从网格中删除它们以节省内存. storyboard-Completed += ref new EventHandlerObject^ ([this,birthImage,index](Object^ sender,Object^ e) { mainGrid-Children-IndexOf (myImage,index); mainGrid-Childre
我有几个图像在Grid容器内动画,我需要在动画结束后从网格中删除它们以节省内存.

storyboard->Completed += ref new EventHandler<Object^> 
   ([this,birthImage,&index](Object^ sender,Object^ e) {
        mainGrid->Children->IndexOf (myImage,&index);
        mainGrid->Children->RemoveAt  (index);
    });

不幸的是我无法关注this suggestion并使用mainGrid-> Chilren->删除(myImage),因为此方法仅适用于C#而不适用于C/C++X

被迫使用IndexOf然后使用RemoveAt会导致并发问题.

我需要一个解决方案来从C/C++X中的View Hierarchy中删除一个对象

在iOS世界中可以用单一的东西完成:[object removeFromSuperView];

解决方法

在我已声明的类标题中

private:
   concurrency::reader_writer_lock myLock;

并将实施改为:

storyboard->Completed += ref new EventHandler<Object^> 
   ([this,birthImage](Object^ sender,Object^ e) {
        unsigned int index;
        myLock.lock();
        if (mainGrid->Children->IndexOf (myImage,&index))
        {
              mainGrid->Children->RemoveAt (index);
        }
        myLock.unlock();
    });

注意unsigned int index的声明作为lambda函数的局部变量.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读