WindowsPhone8 ListBox 实现手风琴折叠菜单效果
发布日期:2021-06-28 22:55:29 浏览次数:2 分类:技术文章

本文共 5144 字,大约阅读时间需要 17 分钟。

WindowsPhone8 ListBox 实现手风琴折叠菜单效果

  XAML示例代码如下:
 
   
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
CS示例代码如下:
//生活指数                String[] lift = _currentApp._address.lifeInfo.Split('\n').ToArray();                Dictionary
dic = new Dictionary
() { }; if (lift != null) { for (int i = 0, len = lift.Length; i < len; i++) { String[] lift2 = lift[i].Split(':').ToArray(); if (lift2.Length == 2 && !dic.Keys.Contains(lift2[0].Trim())) { dic[lift2[0].Trim()] = lift2[1].Trim(); } } } if (dic != null) { //清空 this.lboLifeData.Items.Clear(); int i = 0; foreach (var item in dic) { MyLifeListBoxitem lbitem = new MyLifeListBoxitem(item.Key, item.Value, i); this.lboLifeData.Items.Add(lbitem); i++; } } public class MyLifeListBoxitem : ListBoxItem { #region 全局变量 private int j = new int(); //定义文本 private TextBlock tbk = new TextBlock(); //定义图片 private Image img = new Image(); //定义边框 Border private Border bd = new Border(); //定义父面板 private StackPanel spFather = new StackPanel(); //定义表头面板 private StackPanel spHead = new StackPanel(); //定义内容视图 private ScrollViewer svContent = new ScrollViewer(); #endregion  ///
        /// 构造函数        ///         ///
key        ///
value        ///
public MyLifeListBoxitem(String key, String value, int i) { j = i; //填充数据 if (!String.IsNullOrEmpty(key)) { /***** 表头 *****/ tbk = new TextBlock(); tbk.Text = key; tbk.Style = (System.Windows.Style)Application.Current.Resources["MenuCssText"]; img = new Image(); img.Style = (System.Windows.Style)Application.Current.Resources["MenuCssImage"]; img.ManipulationStarted += img_ManipulationStarted; spHead = new StackPanel(); spHead.Orientation = Orientation.Horizontal; spHead.Children.Add(img); spHead.Children.Add(tbk); /***** 内容 *****/ tbk = new TextBlock(); tbk.Text = value; tbk.TextWrapping = TextWrapping.Wrap; tbk.Style = (System.Windows.Style)Application.Current.Resources["spTwoDaysCss_txt"]; svContent = new ScrollViewer(); svContent.Name = "sv_" + i; svContent.Style = (System.Windows.Style)Application.Current.Resources["ContentCss"]; svContent.Content = tbk; /***** 父面板 *****/ spFather = new StackPanel(); spFather.Background = new SolidColorBrush(Colors.Orange); spFather.Orientation = Orientation.Vertical; spFather.Opacity = 0.85; spFather.Children.Add(spHead); spFather.Children.Add(svContent); /***** 边框 *****/ bd = new Border(); bd.Style = (System.Windows.Style)Application.Current.Resources["MenuCss"]; bd.Child = spFather; this.Content = bd; } } ///
        /// 选项卡伸展/收缩事件        ///         ///
        ///
public void img_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e) { Image img = (Image)sender; if (img != null) { Border bd = (Border)((StackPanel)((StackPanel)img.Parent).Parent).Parent; ScrollViewer sv = (ScrollViewer)bd.FindName("sv_" + j); if (((System.Windows.Media.Imaging.BitmapImage)(img.Source)).UriSource.ToString() == "/Images/new.png") { img.Source = new BitmapImage(new Uri("/Images/minus.png", UriKind.Relative)); bd.Height += 350; sv.Visibility = System.Windows.Visibility.Visible; } else { img.Source = new BitmapImage(new Uri("/Images/new.png", UriKind.Relative)); bd.Height -= 350; sv.Visibility = System.Windows.Visibility.Collapsed; } } e.Complete(); e.Handled = true; } }
源码下载地址:

以上案例仅供学习参考,如有不足之处还请提出指正,谢谢!

效果图如下:

转载地址:https://blog.csdn.net/yimiyuangguang/article/details/19623879 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:HighCharts 图表插件 自定义绑定 时间轴数据
下一篇:WindowsPhon8 ScrollViewer+计时器 实现信息自动滚动播放

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月18日 15时55分36秒