【问题标题】:How can I open a LongListSelector with the groups collapsed in WP7?如何打开在 WP7 中折叠的组的 LongListSelector?
【发布时间】:2013-06-18 09:47:12
【问题描述】:

我有一个显示很多项目的 LongListSelector。打开 longListSelector 后,我看到组已展开,即项目显示在组内。我希望 longList 选择器在开始时显示折叠的面板,仅显示组名。就像一个索引。当您点击一个组时,其项目会展开。如何做到这一点?

【问题讨论】:

    标签: windows-phone-7 longlistselector


    【解决方案1】:

    只需要自己实现 - 如下所示:

    在 XAML 中的项目(不是标题!)模板定义中,绑定包含项目的 Visibility 属性(在我的例子中是 Grid):

    <DataTemplate x:Key="itemTemplate">
      <Grid Visibility="{Binding FolderVisibility}">
      ...
    

    ObservableCollection 派生项目组并创建一个合适的属性来处理展开/折叠状态:

    public class MyGroup : ObservableCollection<MyItem>
    {
        ...
        private bool m_expanded = true;
        public bool Expanded
        {
            get { return m_expanded; }
            set
            {
                m_expanded = value;
                OnPropertyChanged( new PropertyChangedEventArgs( "Expanded" ));
                foreach( var i in this )
                {
                    i.OnFolderCollapsedExpanded();
                }
            }
        }
        ...
    

    最后,您需要每个列表项上的FolderVisibility 属性:

    public class MyItem : INotifyPropertyChanged
    {
        ...
        public event PropertyChangedEventHandler PropertyChanged;
        ...
        public Visibility FolderVisibility
        {
            get { return MyFolder.Expanded ? Visibility.Visible : Visibility.Collapsed; }
        }
        public void OnFolderCollapsedExpanded()
        {
            var h = PropertyChanged;
            if( h != null ) h( this, new PropertyChangedEventArgs( "FolderVisibility" ));
        }
        ...
    

    然后只需在合适的位置切换文件夹的 Expanded 属性(例如,文件夹标题模板的 Click 处理程序)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-13
      • 2019-11-18
      • 2019-09-02
      • 1970-01-01
      • 2019-02-05
      • 2021-04-10
      • 2011-05-20
      • 1970-01-01
      相关资源
      最近更新 更多