Windows phone 7 windows phone 8长列表选择器选择更多添加更多

Windows phone 7 windows phone 8长列表选择器选择更多添加更多,windows-phone-7,windows-phone-8,windows-phone,windows-phone-7.1,Windows Phone 7,Windows Phone 8,Windows Phone,Windows Phone 7.1,我正在关注phonetoolkit longlistselector和中的示例。我正在尝试将showmore功能添加到我的应用程序页面。通常像在longlistselector中一样,我会按字母顺序显示作者,并为每个组显示更多按钮 问题: 这里的问题是,我无法通过按show more按钮添加新作者,而且我也无法在我的longlistselector中更新此内容。我发现在Alphakeygroup类中添加作者(在我上面提到的链接中找到)有问题。我该怎么做 这是我的字母组课 public cla

我正在关注phonetoolkit longlistselector和中的示例。我正在尝试将showmore功能添加到我的应用程序页面。通常像在longlistselector中一样,我会按字母顺序显示作者,并为每个组显示更多按钮

问题: 这里的问题是,我无法通过按show more按钮添加新作者,而且我也无法在我的longlistselector中更新此内容。我发现在Alphakeygroup类中添加作者(在我上面提到的链接中找到)有问题。我该怎么做

这是我的字母组课

  public class AlphaKeyGroup<T> : List<T>
{
    /// <summary>
    /// The delegate that is used to get the key information.
    /// </summary>
    /// <param name="item">An object of type T</param>
    /// <returns>The key value to use for this object</returns>
    public delegate string GetKeyDelegate(T item);

    /// <summary>
    /// The Key of this group.
    /// </summary>
    public string Key { get; private set; }

    /// <summary>
    /// Public constructor.
    /// </summary>
    /// <param name="key">The key for this group.</param>
    public AlphaKeyGroup(string key)
    {
        Key = key;
    }

    /// <summary>
    /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
    /// </summary>
    /// <param name="slg">The </param>
    /// <returns>Theitems source for a LongListSelector</returns>
    private static List<AlphaKeyGroup<T>> CreateGroups(SortedLocaleGrouping slg)
    {
        List<AlphaKeyGroup<T>> list = new List<AlphaKeyGroup<T>>();

        foreach (string key in slg.GroupDisplayNames)
        {
            list.Add(new AlphaKeyGroup<T>(key));
        }

        return list;
    }

    /// <summary>
    /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
    /// </summary>
    /// <param name="items">The items to place in the groups.</param>
    /// <param name="ci">The CultureInfo to group and sort by.</param>
    /// <param name="getKey">A delegate to get the key from an item.</param>
    /// <param name="sort">Will sort the data if true.</param>
    /// <returns>An items source for a LongListSelector</returns>
    public static List<AlphaKeyGroup<T>> CreateGroups(IEnumerable<T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
    {
        SortedLocaleGrouping slg = new SortedLocaleGrouping(ci);
        List<AlphaKeyGroup<T>> list = CreateGroups(slg);

        foreach (T item in items)
        {
            int index = 0;
            if (slg.SupportsPhonetics)
            {
                //check if your database has yomi string for item
                //if it does not, then do you want to generate Yomi or ask the user for this item.
                //index = slg.GetGroupIndex(getKey(Yomiof(item)));
            }
            else
            {
                index = slg.GetGroupIndex(getKey(item));
            }
            if (index >= 0 && index < list.Count)
            {
                list[index].Add(item);
            }
        }

        if (sort)
        {
            foreach (AlphaKeyGroup<T> group in list)
            {
                group.Sort((c0, c1) => { return ci.CompareInfo.Compare(getKey(c0), getKey(c1)); });
            }
        }

        return list;
    }

}
我的xaml.cs文件

   public CategoryFilter()
    {
        InitializeComponent();
        authorsviewmodel = new AuthorsViewModel();
        LoadAuthors();

    }

    private void LoadAuthors()
    {
        List<Author> movies = new List<Author>();
        authorsviewmodel.GetAllAuthors();
        var Authorsgroup = AlphaKeyGroup<Author>.CreateGroups(authorsviewmodel.AuthorsList, System.Threading.Thread.CurrentThread.CurrentUICulture, (Author s) => { return s.AuthorName; }, true);
        AuthorsList.ItemsSource = Authorsgroup;     

    }
public CategoryFilter()
{
初始化组件();
authorsviewmodel=新的authorsviewmodel();
LoadAuthors();
}
私有void LoadAuthors()
{
列表电影=新列表();
authorsviewmodel.GetAllAuthors();
var Authorsgroup=AlphaKeyGroup.CreateGroups(authorsviewmodel.AuthorsList,System.Threading.Thread.CurrentThread.CurrentUICulture,(Author s)=>{return s.AuthorName;},true);
AuthorsList.ItemsSource=作者组;
}
Morecommands类

public class MoreCommand : ICommand
{
    #region ICommand Members

   public bool CanExecute(object parameter)
   {
        return true;
   }


    public event EventHandler CanExecuteChanged;


    public void Execute(object parameter)
    {
        AlphaKeyGroup<Author> list =  parameter as AlphaKeyGroup<Author>;
        Author item = new Author();
        item.AuthorName = "BAIG123";
        list.Add(item);
        AuthorsViewModel authorviewmodel=new AuthorsViewModel();
        authorviewmodel.Authors = parameter as List<AlphaKeyGroup<Author>>;
        authorviewmodel.Authors.Add(list);

    }

    #endregion
}
public类命令:ICommand
{
#区域ICommand成员
公共布尔CanExecute(对象参数)
{
返回true;
}
公共事件处理程序CanExecuteChanged;
public void Execute(对象参数)
{
AlphaKeyGroup list=参数为AlphaKeyGroup;
作者项=新作者();
item.AuthorName=“BAIG123”;
列表。添加(项目);
AuthorsViewModel authorviewmodel=新的AuthorsViewModel();
authorviewmodel.Authors=作为列表的参数;
authorviewmodel.Authors.Add(列表);
}
#端区
}

问题在于,当您修改列表时,您的视图将不会收到更改通知。 您只需将
class AlphaKeyGroup:List
更改为
class AlphaKeyGroup:ObservableCollection
,即可解决此问题

public class MoreCommand : ICommand
{
    #region ICommand Members

   public bool CanExecute(object parameter)
   {
        return true;
   }


    public event EventHandler CanExecuteChanged;


    public void Execute(object parameter)
    {
        AlphaKeyGroup<Author> list =  parameter as AlphaKeyGroup<Author>;
        Author item = new Author();
        item.AuthorName = "BAIG123";
        list.Add(item);
        AuthorsViewModel authorviewmodel=new AuthorsViewModel();
        authorviewmodel.Authors = parameter as List<AlphaKeyGroup<Author>>;
        authorviewmodel.Authors.Add(list);

    }

    #endregion
}