转换成PivotItem用户控件提高WP7加载性能 [英] Convert PivotItem into Usercontrol to improve loading performance in WP7

查看:82
本文介绍了转换成PivotItem用户控件提高WP7加载性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MainPage.xaml中是3 PivotItems枢轴页面。目前它加载所有必要的东西,每个在构造函数的MainPage的PivotItems的。这是不好的,因为它加载了很多东西,是没有必要的。

My MainPage.xaml is a pivot page with 3 PivotItems. Currently it is loading all of the necessary stuff for each of the PivotItems on the MainPage constructor. This is bad because it loads a lot of stuff that are not necessary.

阅读的这里和的这里表明,我只加载第一个PivotItem和加载后,加载项的其余部分。具体做法是:

Reading here and here suggests that I only load the first PivotItem and after it loads, load the rest of the items. Specifically :

通过完善的点播相对于加载在启动时加载的一切Pivot控件内容枢轴应用程序的性能。一种解决方案是利用了来自各PivotItem控制内容,并转换成用户控件。然后,您可以订阅根转轴控制LoadingPivotItem事件。接下来,在事件处理程序,实例化适当的用户控件,并将其设置为PivotItem内容

Improve the performance of the pivot application by loading Pivot control content on-demand as opposed to loading everything at startup. One solution is to take the content from each PivotItem control and convert into UserControls. You can then subscribe to the LoadingPivotItem event on the root pivot control. Next, in the event handler, instantiate the proper UserControl and set it as the PivotItem content.

如果我按照建议:

private void OnLoadingPivotItem(object sender, PivotItemEventArgs e)
{
if (e.Item.Content != null)
{
    // Content loaded already
    return;
}

Pivot pivot = (Pivot)sender;

if (e.Item == pivot.Items[0])
{
    e.Item.Content = new Page1Control();
}
else if (e.Item == pivot.Items[1])
{
    e.Item.Content = new Page2Control();
}
else if (e.Item == pivot.Items[2])
{
    e.Item.Content = new Page3Control();
}
}



我应该使用创建类PageXControl?它应该从主页类某种程度上继承?

I should use create class PageXControl ? Should it inherit somehow from main-page class ?

我如何采取从每个PivotItem控件中的内容,并转换成用户控件?

How do i take the content from each PivotItem control and convert into UserControls ?

感谢

推荐答案

您可以创建自己的枢纽项目,其中将从PivotItem继承。我已经把一个样本的基础上,VS默认枢纽工程,它打出的两个支点项目到自己的类: -

You could create your own Pivot items, which would inherit from PivotItem. I have put together a sample, based on the default Pivot project in VS, which splits out the two Pivot items into their own classes :-

http://www.smartmobiledevice.co.uk/projects/PivotItemUserControlSample.zip

这篇关于转换成PivotItem用户控件提高WP7加载性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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