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