Windows phone 7 如何打开WP7中分组已折叠的LongListSelector?
我有一个长列表选择器,可以显示很多项目。打开longListSelector时,我看到组已展开,即项目显示在组中。我希望长列表选择器显示折叠的面板,在开始时仅显示组名。就像一个索引。轻触组时,其项将展开。如何做到这一点?我只需要自己实现这一点-按如下方式完成: 在XAML中的项(而不是标题!)模板定义中,绑定包含项的Windows phone 7 如何打开WP7中分组已折叠的LongListSelector?,windows-phone-7,longlistselector,Windows Phone 7,Longlistselector,我有一个长列表选择器,可以显示很多项目。打开longListSelector时,我看到组已展开,即项目显示在组中。我希望长列表选择器显示折叠的面板,在开始时仅显示组名。就像一个索引。轻触组时,其项将展开。如何做到这一点?我只需要自己实现这一点-按如下方式完成: 在XAML中的项(而不是标题!)模板定义中,绑定包含项的可见性属性(在我的例子中是网格): 最后,每个列表项都需要FolderVisibility属性: public class MyItem : INotifyPropertyChang
可见性
属性(在我的例子中是网格
):
最后,每个列表项都需要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" ));
}
...
然后只需在适当的位置切换文件夹的展开的
属性(例如,文件夹标题模板的单击
处理程序)
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();
}
}
}
...
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" ));
}
...