1

我只是在Silverlight 5中使用PivotViewer控件。好像很多事情都得到了改进,但我遇到了一些问题,显示了我在Silverlight下完美工作的旧.cxml集合4将Silverlight 4中的数据透视表视图集合移动到Silverlight 5

旧的方式代码:

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; 

会发生什么情况是显示了项目,但筛选器窗格中没有显示任何内容,如果选择了项目,则不再有任何描述!

回答

2

发生的是_cxml.ItemsProperties直到CxmlCollectionSource下载并处理.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

+0

非常感谢。您的博客正在解决我的许多问题! – sparaflAsh 2012-03-29 14:58:08