I'm just playing around with PivotViewer control in Silverlight 5. It seems like many things got improved, but I'm having some issues displaying my old .cxml collections that perfectly worked under Silverlight 4

The old way to code:

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

translates now to something like:

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;

What happens is that Items are shown, but nothing shows up in the filter pane and, if an item is selected, there is no longer any description for them!

有帮助吗?

解决方案

What is happening is that _cxml.ItemsProperties is not loaded until after the CxmlCollectionSource downloads and processes the .cxml file. CxmlCollectionSource has a StateChanged event. If you check to see if the State is Loaded, then you can map the _cxml properties to the PivotViewer.

Here is a sample of what this would look like:

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

I have a more in depth description of this on my blog.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top