开发者

Windows Phone 7 Control Caching - 'Element is already the child of another element'

开发者 https://www.devze.com 2023-02-05 04:19 出处:网络
I\'m trying to speed up my windows phone 7 page load times.I have a \'static\' page that has a dynamically created in a Panorama control - static meaning that the content never changes.

I'm trying to speed up my windows phone 7 page load times. I have a 'static' page that has a dynamically created in a Panorama control - static meaning that the content never changes.

On the first load I look at my config file, create the individual PanoramaItem controls and add them to the main Panorama control. I'm trying to keep a List in a static place so that the initial creation would only happen once and I could just add a fully rendered version to my Panorama control when the page was rendered.

Works fine on first load, but when I try to add the cached PanoramaItems to the Panorama control I get the message "Element is already the child of another element". This makes sense since I already added before. But I can see a way to disconnect the PanoramaItems with the first Panorama control...

I could be going about the control cachin开发者_JS百科g thing all wrong as well... Let me know if there's another way to do this.


You can use Panorama.Items.Remove(pivotItem) for this

As an example

With the following page fields

PanoramaItem pi;
bool blahShown = false;

On the press of this button, the control is first instantiated and displayed and on subsequent presses removed and readded without instantiation.

private void button1_Click(object sender, RoutedEventArgs e)
{

    if (pi == null) {
        pi = new PanoramaItem();
        pi.Header = "blah";
    }

    if (blahShown) {
        Pano.Items.Remove(pi);
        blahShown = false;
    } else {
        Pano.Items.Add(pi);
        blahShown = true;
    }


}
0

精彩评论

暂无评论...
验证码 换一张
取 消