silverlight中常用公共函数分享
UserControl自动调整大小
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800"
//处理后台传过来的时间类型的空值(若后台传得时空值在异步交互过程中silverlight接受到的其实是一个默认值为0001-01-01的时间值)
public static string DateToString(DateTime dt, string format = "yyyy-MM-dd")
{
string str = dt.ToString(format);
if (str.Contains("0001"))
return "";
else
return str;
}
/// <summary>
/// 设置radioButton 值
/// </summary>
/// <param name="list"></param>
public static void setRadioButtion(List<RadioButton> list, string groupName, string value)
{
if (null != list && list.Count > 0)
{
foreach (RadioButton radioButton in list.Where(r => r.GroupName == groupName).ToList())
{
if (!String.IsNullOrEmpty(value) && radioButton.Tag.ToString().Equals(value))
{
radioButton.IsChecked = true;
break;
}
}
}
}
/// <summary>
/// 得到radioButton 值
/// </summary>
/// <param name="list">radioButton List</param>
/// <param name="groupName">radioButton groupName</param>
/// <param name="ILogic">1返回tag 2返回content</param>
/// <returns></returns>
public static string getRadioButton(List<RadioButton> list, String groupName, int ILogic)
{
if (null != list && list.Count > 0)
{
foreach (RadioButton radioButton in list.Where(r => r.GroupName == groupName).ToList())
{
if (radioButton.IsChecked == true && ILogic == 1)
{
return radioButton.Tag.ToString();
}
if (radioButton.IsChecked == true && ILogic == 2)
{
return radioButton.Content.ToString();
}
}
}
return string.Empty;
}
/// <summary>
/// 设置checkBox控件是否被选中
/// </summary>
/// <param name="checkbox">控件名称</param>
/// <param name="value">0不选中,1选中</param>
public static void setCheckBox(CheckBox checkbox, String value)
{
int temp = (value == null || value.Trim().Equals("")) ? 0 : int.Parse(value);
if (temp == 1)
checkbox.IsChecked = true;
}
//设置值
public static string getCheckBoxValue(CheckBox checkbox)
{
if (checkbox.IsChecked == true)
return "1";
else
return "0";
}
//设置实体的radiobutton的值
public static string returnRadioButtonValue(List<RadioButton> list, string groupName)
{
if (list != null)
{
foreach (RadioButton temp in list.Where(r => r.GroupName == groupName).ToList())
{
if (temp.IsChecked == true)
return temp.Tag.ToString();
}
}
return "0";
}
/// <summary>
/// 设置实体的CheckBox的值
/// </summary>
/// <param name="data"></param>
/// <param name="index"></param>
/// <returns></returns>
public static bool setCheckBoxBySplit(string data, int index)
{
string[] datas = data.Split(',');
try
{
if (datas[index] == "1")
return true;
else
return false;
}
catch
{
return false;
}
}
//设置下拉列表的绑定项
public static int getComboxSelectValue(ComboBox cmb, string value)
{
int flag = 0;
int index = -1;
if (value == null || value.Trim().Equals(""))
return index;
foreach (ComboBoxItem temp in cmb.Items)
{
index++;
if (temp.Tag.ToString() == value)
{
flag = 1;
break;
}
}
if (flag == 0)
return -1;
return index;
}
/// <summary>
/// 获取子元素
/// </summary>
/// <param name="root"></param>
/// <returns></returns>
public static IEnumerable<DependencyObject> Descendents(DependencyObject root)
{
if (root.GetType() == typeof(TabControl))
{
TabControl tab = root as TabControl;
TabItem tabItem = tab.Items[0] as TabItem;
root = (DependencyObject)tabItem.Content;
}
int count = VisualTreeHelper.GetChildrenCount(root);
for (int i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(root, i);
yield return child;
foreach (var descendent in Descendents(child))
yield return descendent;
}
}
/// <summary>
/// 检查combobox 选空返回NULL
/// </summary>
/// <param name="cmb">控件名称</param>
/// <param name="ReturnValue">1为codeValue 2为Tag</param>
/// <returns></returns>
public static string CheckCombobox(ComboBox cmb, int ReturnValue)
{
if (cmb.SelectedItem != null && ReturnValue == 1)
{
return cmb.SelectedItem.GetPropertyValue("codeValue").toTrim();
}
if (cmb.SelectedItem != null && ReturnValue == 2)
{
return cmb.SelectedItem.GetPropertyValue("Tag").toTrim();
}
else
{
return null;
}
}
转载于:https://www.cnblogs.com/share-silverlight/archive/2011/08/19/2145396.html
silverlight中常用公共函数分享相关推荐
- MapInfo中常用查询函数及用法
MapInfo中常用查询函数及用法: 函数用途 语法 备注 图层中选点 Str$(obj)="point": Str(String)表示字符串:point表示点: 图层中选线 St ...
- ML之sklearn:sklearn.metrics中常用的函数参数(比如confusion_matrix等 )解释及其用法说明之详细攻略
ML之sklearn:sklearn.metrics中常用的函数参数(比如confusion_matrix等 )解释及其用法说明之详细攻略 目录 sklearn.metrics中常用的函数参数 con ...
- Matlab:Matlab中常用的函数、案例详细攻略
Matlab:Matlab中常用的函数.案例详细攻略 目录 常用函数 1.与文件相关 2.MATLAB GUI不同控件函数间变量传递方法 常用函数 Matlab中的bwmorph函数解释 bwmorp ...
- Tkinter中常用的函数
Tkinter中常用的函数 窗口管理器的刷新事件 窗口管理器的刷新事件 ps:一个Tkinter应用在绝大部分时间都花费在内部的时间循环上(通过mainloop方法进入).事件来自于各种途径.包括来自 ...
- hive获取月份_【Hive】Hive中常用日期函数整理
前言 使用hive进行时间处理的过程中,有时忘记一些常用的函数用法,现整理一下hive中常用日期函数,当做备忘录使用,忘记来翻阅一下. 1 时间戳转化日期函数 时间戳必须是10位,默认情况下转化为'y ...
- Mysql中常用的函数汇总
Mysql中常用的函数汇总: 一.数学函数 abs(x) 返回x的绝对值 bin(x) 返回x的二进制(oct返回八进制,hex返回十六进制) ceiling(x) 返回大于x的最小整数值 exp(x ...
- Golang字符串中常用的函数
Golang字符串中常用的函数 说明: 字符串在我们程序开发中,使用的是非常多的,常用的函数需要同学们掌握: 下面列出20种常用的字符串函数: 1)统计字符串的长度,按字节len(str) 2)字符串 ...
- roscpp中常用的函数、类以及命名空间
roscpp中常用的函数.类以及命名空间 前言 前言 经过了一段时间的ros与gazebo机器人编队仿真的学习,对ros的结构有了一定了解,接下来将对松灵机器人的底盘进行实车开发,主要开发语言使用C+ ...
- jQuery中常用的函数方法总结
jQuery中为我们提供了很多有用的方法和属性,自己总结的一些常用的函数,方法.个人认为在www.21kaiyun.com的紫微斗数星座在线排盘开发中会比较常用的,仅供大家学习和参考. 事件处理 re ...
最新文章
- Struts2请求参数合法性校验机制
- c++函数模板(c++细节篇十)
- poj 1061 青蛙的约会
- 百度搜索与推荐引擎的云原生改造
- java类结构图_java 集合类结构图
- SAP Spartacus Template-Driven Outlets
- Unity 开发和配置
- 项目管理控件Project Management Library
- shell数值大小的比较
- 【QT】QT从零入门教程(十五):QImage和Mat的转换
- linux7配置永久路由,CentOS7添加永久路由
- Spring Framework--Data Access(1)--Transaction Management(2) - 声明式事务管理
- Access数据库的模糊查询
- matlab dmc控制代码,动态控制矩阵(DMC)算法的浅析
- 融云技术分享:融云安卓端IM产品的网络链路保活技术实践
- tb项目管理实践_项目 管理 数据库
- C语言-随机产生10以内四则运算
- QXRService:高通SnapdragonXR OpenXR SDK v1.x 概略
- 自签名SSL证书有风险吗?
- 洛谷-P2198 杀蚂蚁
热门文章
- 【springboot】spring-boot-devtools 热部署 导致 mvn spring-boot:run 出现异常
- c++使用netsh命令_渗透常用命令IPC$内网(一)
- php数据库录入和输出,PHP数据库之CURD操作
- python如何定义一个空变量_如何在python中定义自由变量? - python
- Spark SQL之DataSet
- 在对比了 GitHub 5000 个 Python 项目之后,我们精选出了这 36 个!
- 在python中、处理的一切都是对象_Python 3+ 一切都是对象
- linq php,C#开始使用 LINQ (上)
- supervisor nginx_Supervisor 的使用和进阶 (3)
- squid 不缓存特定页面_【零基础学云计算】squid代理服务器介绍与配置(理论+实践)一...