[WP7]实现类似tree效果
2011-08-25 17:02
183 查看
#目的
实现tree效果。
#前提条件
需要区分WP7.0和WP7.1+版本。
对于WP7.0版本,可采用Listbox嵌套listbox方法实现;
对于WP7.1+(Mango)版本,则多一项选择,采用系统的toolkit方法,即ExpanderView实现。
#实现过程
本文目前采用listbox嵌套方法实现。(demo,有bug。。。)
1.无需声明命名空间。
2.demo.xaml中使用如下代码:
声明控件使用:
#效果
#遗留问题
1.目前在Chapter*上点住时,无法响应拖动事件。
2.打开Book目录时,有时不能将当前打开的作为展现页面呈现出来。
实现tree效果。
#前提条件
需要区分WP7.0和WP7.1+版本。
对于WP7.0版本,可采用Listbox嵌套listbox方法实现;
对于WP7.1+(Mango)版本,则多一项选择,采用系统的toolkit方法,即ExpanderView实现。
#实现过程
本文目前采用listbox嵌套方法实现。(demo,有bug。。。)
1.无需声明命名空间。
2.demo.xaml中使用如下代码:
<!--ContentPanel - tree with item and sub item--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="4,4,4,4"> <ListBox x:Name="MainList"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel > <TextBlock Text="{Binding Name}" MouseLeftButtonDown="Text_MouseLeftButtonDown" FontSize="40"></TextBlock> <ListBox Visibility="Collapsed" ItemsSource="{Binding Chapters}"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="5"> <TextBlock Text="{Binding Title}" FontSize="30"> </TextBlock> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid>3.在demo.xaml.cs中使用如下代码:
声明控件使用:
using System.Collections.ObjectModel;代码实现:
public treeListPage() { InitializeComponent(); ObservableCollection<Book> books = new ObservableCollection<Book>(); for (int i = 0; i < 10; i++) { Book book = new Book { Name = "Book" + i.ToString()}; book.Chapters = new List<Chapter>(); for (int j = 0; j < 10; j++) book.Chapters.Add(new Chapter { Title = "Chapter" + i.ToString() + "_" + j.ToString()}); books.Add(book); } this.MainList.ItemsSource = books; } public class Book { public string Name { get; set; } public List<Chapter> Chapters { get; set; } } public class Chapter { public string Title{get;set;} public string Page{get;set;} } private void Text_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { TextBlock t = sender as TextBlock; StackPanel p = VisualTreeHelper.GetParent(t) as StackPanel; ListBox sublist = p.Children[1] as ListBox; if (sublist.Visibility == Visibility.Collapsed) sublist.Visibility = Visibility.Visible; else sublist.Visibility = Visibility.Collapsed; } private void Text_MouseLeftButtonDown2(object sender, MouseButtonEventArgs e) { }
#效果
#遗留问题
1.目前在Chapter*上点住时,无法响应拖动事件。
2.打开Book目录时,有时不能将当前打开的作为展现页面呈现出来。
相关文章推荐
- silverlight使用DataGrid实现类似Treelistview效果
- 修改TreeList单元格格式(实现类似单元格合并效果)
- easyui treegrid的拖拽效果实现
- Android 中的用HorizontalScrollView布局实现类似Gallery效果
- scala 实现类似reduceByWindown的效果
- 基于Qt的类似QQ好友列表抽屉效果的实现
- 原生js实现类似弹窗抖动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- Jquery实现类似选择邮箱发送人效果
- vue-cli 路由 实现类似tab切换效果(vue 2.0)
- 基于jquery实现的文字向上跑动类似跑马灯的效果
- 使用script的src实现跨域和类似ajax效果
- Android实现通用的ActivityGroup(效果类似Android微博客户端主界面),强烈建议不要再使用TabActivity
- Js实现类似图片相册左右切换效果
- 论坛源码推荐(4月16日):类似FourSquare的视差效果 实现简单的颜色实例化
- 类似 MSDN CSDN 导航树效果 ASP.Net(C#) + JavaScript 实现!
- 如何在 iOS 7 中设置 barTintColor 实现类似网易和 Facebook 的 navigationBar 效果
- Java之简单的图片动态显示(实现类似GIF动画效果)
- Android中使用TabHost实现类似标签栏的效果