Windows Phone中的自定义跳转列表

时间:2014-06-20 23:32:58

标签: c# windows-phone-8 jump-list

我一直在看这个:http://code.msdn.microsoft.com/wpapps/Custom-LongList-Selector-bf8cb9ad并尝试合并到我的应用中。但是,由于我的数据加载方式不同,因此有点混乱。现在,我有两个错误CustomKeyGroup的最佳重载方法匹配< .ViewModels.SoundData> .GetSoundGroups(System.Collections.Generic.List< .ViewModels.SoundData>)'有一些无效的参数

参数1:无法从'string'转换为'System.Collections.Generic.List'

错误发生在'CustomKeyGroup.GetSoundGroups(mvm.Items);'来自mainpage.cs。我知道这些物品是个问题。如果您查看链接,他们会以不同的方式加载数据/ listmovie.add。

我知道有些东西搞砸了很长时间,但由于我的数据加载不同,我努力让它正常工作。

我想拥有位于我的SoundModel中的群组(Alpha,Bravo等)的自定义跳转列表。这是一部分:

namespace T.ViewModels
{
    public class SoundModel: BindableBase
    {
        public SoundGroup NewAdds { get; set; }
        public SoundGroup Software { get; set; }

        }

        public bool IsDataLoaded { get; set; }



        public void LoadData()
        {
            // Load data into the model
            Software = CreateSoftwareGroup();
            NewAdds = CreateNewAddsGroup();


            IsDataLoaded = true;
        }

        private SoundGroup CreateNewAddsGroup()
        {
            SoundGroup data = new SoundGroup();
            data.Title = "New";
            string basePath = "assets/audio/newadds/";

               data.Items.Add(new SoundData
            {
                Title = "Test1",
                FilePath = basePath + "Test.mp3",
                Groups = "Alpha"
            });



            data.Items.Add(new SoundData
            {
                Title = "Test2",
                FilePath = basePath + "Test2.mp3",
                Groups="Bravo"
            });


            data.Items.Add(new SoundData
            {
                Title = "Test3",
                FilePath = basePath + "Test3.mp3",
                Groups= "Zulu"
            });

  private SoundGroup CreateSoftwareGroup()
        {
            SoundGroup data = new SoundGroup();

            data.Title = "Software";
            string basePath = "assets/audio/Software/";

            data.Items.Add(new SoundData
            {
                Title = "Test1",
                FilePath = basePath + "Test.mp3",
                Groups = "Alpha"
            });

            data.Items.Add(new SoundData
            {
                Title = "Test2",
                FilePath = basePath + "Test2.mp3",
                Groups="Bravo"
            });


            data.Items.Add(new SoundData
            {
                Title = "Test3",
                FilePath = basePath + "Test3.mp3",
                Groups= "Zulu"
            });

以下是相关的mainpage.cs:

SoundData mvm = new SoundData();

            this.LongList.ItemsSource = CustomKeyGroup<SoundData>.GetSoundGroups(mvm.Items);

SoundGroup:

{
    public class SoundGroup
    {
        public SoundGroup()
        {
            Items = new List<SoundData>();
        }

        public List<SoundData> Items { get; set; }
        public string Title { get; set; }
        public string Groups { get; set; }

    }
}

SoundData:

{
    public class SoundData : ViewModelBase
    {
        public string Title { get; set; }
        public string FilePath { get; set; }
        public string Items { get; set; }
        public string Groups { get; set; }


        public RelayCommand<string> SaveSoundAsRingtone { get; set; }


        private void ExecuteSaveSoundAsRingtone(string soundPath)
        {
            App.Current.RootVisual.Dispatcher.BeginInvoke(() =>
            {
                SaveRingtoneTask task = new SaveRingtoneTask();
                task.Source = new Uri("appdata:/" + this.FilePath);
                task.DisplayName = this.Title;
                task.Show();
            }
                );
        }   

        public SoundData()
        {
            SaveSoundAsRingtone = new RelayCommand<string>(ExecuteSaveSoundAsRingtone);
        }

    }
}

1 个答案:

答案 0 :(得分:0)

到目前为止,我可以看到你应该调用下面的函数

SoundModel svm = new SoundModel();
svm.LoadData();

this.LongList.ItemsSource = CustomKeyGroup<SoundData>.GetSoundGroups(svm.Software.Items);

this.LongList.ItemsSource = CustomKeyGroup<SoundData>.GetSoundGroups(svm.NewAdds.Items);

原因是您需要在方法Generic.List<.ViewModels.SoundData>中传递GetSoundGroups,并且该列表包含在SoundGroup类中。由于您加载的数据在SoundModel级以内,因此我可能只考虑上述实现。