【问题标题】:Custom Jump lists in Windows PhoneWindows Phone 中的自定义跳转列表
【发布时间】:2023-03-27 02:38:01
【问题描述】:

我一直在看这个: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);

声音组:

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

    }
}

声音数据:

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

    }
}

【问题讨论】:

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


    【解决方案1】:

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

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

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

    原因是您需要在方法GetSoundGroups 中传递Generic.List&lt;.ViewModels.SoundData&gt;,并且列表包含在SoundGroup 类中。由于您加载的数据在 SoundModel 类中,所以我可能只能想到上述实现。

    【讨论】:

    • 对不起,因为我还没有足够的代表,所以不能投票给你,但那是正确的。错误消失了,现在我只需要调整我的组标题和跳转列表模板。谢谢你pushpraj!
    • 太好了,问题解决了。即使您无法投票,您也可以接受此答案。快乐编码:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多