每次在HeaderedContentControl中创建新实例 [英] Creates new instance everytime in HeaderedContentControl

查看:58
本文介绍了每次在HeaderedContentControl中创建新实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个名为CurrentPage(例如B类型)的属性,该属性绑定到HeaderedContentControl的内容.

并且我有一个名为MyPages的B类型集合(所有实例都在这里创建一次).

现在当我说CurrentPage = MyPages [0];它会创建一个新实例,尽管它不会创建一个实例.

用同样的方式当我说CurrentPage = MyPages [1];再次创建一个新实例.

我不明白为什么要这么做.

每次我执行上述任务时,它都会消耗内存.

这是什么原因?

预先谢谢您

Hi,

I have a property named CurrentPage(eg: B type) bound to Content of HeaderedContentControl.

and I have a collection of B type named MyPages (All the instances have been created here once).

Now when I say CurrentPage = MyPages[0]; it creates a new instance though it does not go to create one.

Same way When I say CurrentPage = MyPages[1]; again it creates a new instance.

I am not getting why it does this.

It consumes memory every time I do above kind of assignment.

What would be the cause here?

Thank you in advance

推荐答案

只是一个猜测:也许MyPages集合是某种自定义类型的,并且在使用索引调用时实例化了所请求对象的副本吗? />
代码类似于
Just a guess: Maybe the MyPages collection is of some custom type and instantiates a copy of the requested object when called with an index?

The code would be something like
public class MyPagesCollection
{
    private List<page> _innerList = new List<page>();

    public this[int index]
    {
        get
        {
            Page page = _innerList[index].Copy();

            DoSomethingImportantWith(page);

            return(page);
        }
    }
}</page></page>



通常,很难不看相关的代码.



In general, it''s hard to say without seeing the relevant code.


这篇关于每次在HeaderedContentControl中创建新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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