【问题标题】:Moving Pivotviewer Collections from Silverlight 4 to Silverlight 5将 Pivotviewer 集合从 Silverlight 4 移动到 Silverlight 5
【发布时间】:2012-03-29 09:43:47
【问题描述】:

我只是在 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;

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

【问题讨论】:

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


    【解决方案1】:

    发生的情况是_cxml.ItemsProperties 直到CxmlCollectionSource 下载并处理.cxml 文件之后才加载。 CxmlCollectionSource 有一个 StateChanged 事件。如果您检查State 是否为Loaded,则可以将_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;
            }
        }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多