1

我只是在 Silverlight 5 中使用 PivotViewer 控件。似乎很多事情都得到了改进,但我在显示.cxml在 Silverlight 4 下完美运行的旧集合时遇到了一些问题

旧的编码方式:

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;

发生的情况是显示了项目,但过滤器窗格中没有显示任何内容,如果选择了一个项目,则不再有任何描述!

4

1 回答 1

2

发生的事情是_cxml.ItemsProperties直到CxmlCollectionSource下载和处理.cxml文件之后才加载。 CxmlCollectionSource有一个StateChanged事件。如果您检查是否StateLoaded,则可以将_cxml属性映射到 PivotViewer。

这是一个示例:

        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;
        }
    }

的博客对此有更深入的描述

于 2012-03-29T14:09:30.507 回答