WP7中对ListBox的ItemTemplate中子元素的后台操作
<ListBox x:Name="FirstListBox" ItemsSource="{Binding mFriends}" Margin="0,-6,-12,0" Height="541"><ListBox.ItemTemplate><DataTemplate><Border x:Name="borderListBox" Margin="5" CornerRadius="3"><StackPanel Orientation="Horizontal"><Image Height="80" Margin="20" Width="80" Source="{Binding Image_Url}"></Image><StackPanel><StackPanel Orientation="Horizontal"><TextBlock Margin="0,10,0,0" Text="{Binding Name}" FontFamily="/Fonts/YGY20070701.ttf#叶根友钢笔行书简体" Foreground="{StaticResource UseNameUnSelectedBrush}" TextWrapping="Wrap" FontSize="28"/><Image Name="VipImage" Source="{Binding Vip}" Width="32" Height="32"></Image></StackPanel><TextBlock Width="328" Text="{Binding message}" Foreground="Black" TextWrapping="Wrap"/></StackPanel> </StackPanel></Border></DataTemplate></ListBox.ItemTemplate></ListBox>
if(back =="#FF000000")
{
for(inti =0; i <FirstListBox.Items.Count; i++)
{
ListBoxItem item =this.FirstListBox.ItemContainerGenerator.ContainerFromIndex(i) asListBoxItem;
StackPanel border =FindFirstElementInVisualTree<StackPanel>(item);
border.Background =newSolidColorBrush(Color.FromArgb(170, 255, 255, 255));
}
}
else
{
for(inti =0; i <FirstListBox.Items.Count; i++)
{
ListBoxItem item =this.FirstListBox.ItemContainerGenerator.ContainerFromIndex(i) asListBoxItem;
StackPanel border =FindFirstElementInVisualTree<StackPanel>(item);
border.Background =newSolidColorBrush(Color.FromArgb(255, 34, 34, 34));
}
}
privateT FindFirstElementInVisualTree<T>(DependencyObject parentElement) whereT : DependencyObject
privatevoid SearchVisualTree(DependencyObject targetElement) { var count = VisualTreeHelper.GetChildrenCount(targetElement); if (count ==0) return; for (int i =0; i < count; i++) { var child = VisualTreeHelper.GetChild(targetElement, i);if (child is StackPanel) { StackPanel targetItem = (StackPanel)child; var back = Application.Current.Resources["PhoneBackgroundColor"].ToString();if (back =="#FF000000") { targetItem.Background =new SolidColorBrush(Color.FromArgb(255, 34, 34, 34)); }else { targetItem.Background =new SolidColorBrush(Color.FromArgb(170, 255, 255, 255)); } }else { SearchVisualTree(child); } } }
this .SearchVisualTree( this .FirstListBox);
|
转载于:https://www.cnblogs.com/songtzu/archive/2012/11/02/2750783.html
WP7中对ListBox的ItemTemplate中子元素的后台操作相关推荐
- html5盒子层级设置,解决CSS中子元素z-index与父元素兄弟节点的层级问题
1.问题的出现 写了一个平铺的列表,其中有些列表项具有hover出现的弹出框.希望达成的目标是弹出框展现时,要把列表项内容遮盖住,以保证弹出框内容优先展示. 元素的结构大致如下: 列表项1 弹出框1 ...
- python list元素合并_Python程序中使用表达式合并List列表元素 - Python - 服务器之家...
Python程序中使用表达式合并List列表元素 发布时间:2014-02-06 来源:服务器之家 在实现一个产品过程中,使用 Python Extension 需要一个语句将一个列表中子列表合并成为 ...
- CSS样式中伪类和伪类元素的区别(css中一个冒号和两个冒号的区别)
首先介绍下什么是伪类,所谓伪类就是: 伪类选择元素基于的是当前元素处于的状态,或者说元素当前所具有的特性,而不是元素的id.class.属性等静态的标志.由于 状态是动态变化的,所以一个元素达到一个特 ...
- php判断数组不重复的元素,php从数组中随机选择若干不重复元素
php从数组中随机选择若干唯一元素 /* * $array = the array to be filtered * $total = the maximum number of items to r ...
- 【Groovy】集合遍历 ( 使用集合的 findAll 方法查找集合中符合匹配条件的所有元素 | 代码示例 )
文章目录 一.使用集合的 findAll 方法查找集合中符合匹配条件的所有元素 1.闭包中使用 == 作为 findAll 方法的查找匹配条件 2.闭包中使用 is 作为 findAll 方法的查找匹 ...
- leetcode 215.数组中的第K个最大元素
难度:中等 频率:250 ** 题目:给定整数数组nums和整数k,清返回数组中第K个最大的元素. 清注意你要找的是数组排序后的第K个最大的元素,而不是第K个不同的元素. ** ** 题目类型: 经典 ...
- 《漫画算法2》源码整理-8 链表中倒数第K个节点元素
链表中倒数第K个节点元素 public class KthFromEnd {public static Node findKthFromEnd(Node head, int k){Node p1 = ...
- 找出一个数组中出现次数最多的那个元素
Description 找出一个数组中出现次数最多的那个元素 Input 多组输入,请处理到文件结束 每组第一行输入一个整数n(不大于20) 第二行输入n个整数 Output 找出n个整数中出现次数最 ...
- python中列表实现自加减元素_python初学者知识整合
python 第一章:概述 1. 概述 Python是一门跨平台.开源.免费的解释型高级动态编程语言. ① 编译:笔译,用理解原文本 ② 解释:口译,逐字逐句解释,不产生新文本 Python中的可迭代 ...
最新文章
- 41、应用如何签名以及签名的意义(转载)
- 一个popup弹窗实现思路--(基于mintui分析)
- Ambari安装之部署3个节点的HA分布式集群
- Java中的==和equals区别
- ASP.NET的五大数据控件分析
- Eclipse关闭XML文件验证的方法
- Eclipse 隐藏已关闭的项目
- 大数据学习——yarn集群启动
- react-native开发安卓app相关使用总结
- win7计算机屏幕休眠,windows7系统怎么设置屏幕不休眠
- openCV——轮廓检测
- C++语言分号的使用
- 强化学习从K-摇臂老虎机开始
- 电脑提示Wtautoreg.exe无法找到入口怎么解决?
- 动力节点『lol版』Java学习路线图(四)Javaweb阶段
- 什么是“可维护性”?
- 安卓中COLOR的值分析
- Gradle本地化构建技巧之自定义Gradle配置文件
- Django之Cookie和 Session
- 欢迎潍坊市委组织部副部长都焕德一行莅临润达软件考察指导