将Pivotviewer集合从Silverlight 4移动到Silverlight 5

时间:2012-03-29 09:43:47

标签: c# silverlight silverlight-5.0 pivotviewer cxml-collectionxml

我只是在Silverlight 5中使用PivotViewer控件。看起来很多东西都得到了改进,但是我有一些问题显示我在Silverlight 4下完美运行的旧.cxml集合

旧的代码方式:

InitializeComponent();
MainPivotViewer.LoadCollection("http://localhost:4573/ClientBin/Actresses.cxml",              string.Empty);

现在翻译成:

InitializeComponent();
CxmlCollectionSource _cxml = new CxmlCollectionSource(new Uri("http://localhost:1541/ClientBin/Actresses.cxml", UriKind.Absolute));
PivotMainPage.PivotProperties = _cxml.ItemProperties.ToList();
PivotMainPage.ItemTemplates = _cxml.ItemTemplates;
PivotMainPage.ItemsSource = _cxml.Items;

会显示项目,但过滤器窗格中没有显示任何内容,如果选择了某个项目,则不再有任何描述!

1 个答案:

答案 0 :(得分:2)

发生的事情是_cxml.ItemsPropertiesCxmlCollectionSource下载并处理.cxml文件之后才会加载。 CxmlCollectionSourceStateChanged个事件。如果您检查State是否为Loaded,则可以将_cxml属性映射到数据透视表。

以下是一个示例:

        private CxmlCollectionSource _cxml;
    void pViewer_Loaded(object sender, RoutedEventArgs e)
    {
        _cxml = new CxmlCollectionSource(new Uri("http://myurl.com/test.cxml",
                                             UriKind.Absolute));
        _cxml.StateChanged += _cxml_StateChanged;
    }

    void _cxml_StateChanged(object sender,
                           CxmlCollectionStateChangedEventArgs e)
    {
        if(e.NewState == CxmlCollectionState.Loaded)
        {
            pViewer.PivotProperties =
                       _cxml.ItemProperties.ToList();
            pViewer.ItemTemplates =
                       _cxml.ItemTemplates;
            pViewer.ItemsSource =
                       _cxml.Items;
        }
    }

我有a more in depth description of this on my blog