sing System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace MyLib.Extensions {
/// <summary>
/// Description of WpfExt.
/// </summary>
public static class WpfExt {
public static List<childItem> FindVisualChildren<childItem>(this DependencyObject obj)
where childItem : DependencyObject {
List<childItem> children = new List<childItem>();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) {
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem) {
children.Add(child as childItem);
} else {
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null) {
children.Add(childOfChild as childItem);
}
}
}
return children;
}
public static childItem FindVisualChild<childItem>(this DependencyObject obj)
where childItem : DependencyObject {
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) {
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem)
return (childItem)child;
else {
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
}
}
posted @ 2008-10-20 04:05 XMLSpy 阅读(203) 评论(0)
编辑
看到一则新闻:
"新华网报道,据民政部统计显示,8月8日,北京奥运开幕当日,全国民政部门迎来了新中国成立以来规模最大的日结婚登记高峰。"
看来,离婚高峰很快就会来了.
太多人跟着闹运会一起发昏.
可称之为: 脑晕会
posted @ 2008-08-09 21:58 XMLSpy 阅读(78) 评论(1)
编辑
为你的程序切换主题,这个主题不是随着系统变化的,而是你程序专有的,
无论系统主题如何变化,你的程序就是当前这个德行----就是不变!
注意:
1.需要.net3.5
2.当中的"OFFICE2007"主题需要Assergs.Windows.dll . 这个是比较不错的开源Office2007风格的框架.
项目地址: http://www.codeplex.com/appfx/Wiki/View.aspx?title=Home&version=17
3.其他的dll的位置都在源码文件中的注释写清楚了,敬请品尝!

Code
using System;
using System.Windows;
using Assergs.Windows;
namespace XMLSpy.WPF.Util{
/// <summary>
/// ThemeSwitcher所使用的主题枚举
/// </summary>
[Flags]
public enum ThemeEnum{
CLASSIC = 1,
ROYALE = 2,
LUNA = 4,
LUNA_HOMESTEAD = 8,
LUNA_METALLIC = 16,
/// <summary>
/// Vista默认主题
/// </summary>
AERO = 32,
/// <summary>
/// Office2007主题
/// </summary>
OFFICE2007 = 64
}
/// <summary>
/// Theme切换
/// </summary>
public class ThemeSwitcher{
/// <summary>
/// 切换Theme
/// </summary>
/// <param name="theme">Theme枚举</param>
/// <param name="element">FrameworkElement对象</param>
public static void SwitchTheme(ThemeEnum theme, FrameworkElement element){
element.Resources.MergedDictionaries.Add(GetThemeResourceDictionary(theme));
}
//public static void UnloadTheme(ThemeEnum theme,FrameworkContentElement element) {
// element.Resources.MergedDictionaries.Remove(GetThemeResourceDictionary(theme));
//}
public static ResourceDictionary GetThemeResourceDictionary(ThemeEnum theme){
Uri uri = null;
//==================== OFFICE2007 ======================================
//Assergs.Windows.dll
//office2007
if (theme == ThemeEnum.OFFICE2007){
return new OfficeStyle();
}
switch (theme){
//==================== CLASSIC ======================================
//C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Classic.dll
//classic
case ThemeEnum.CLASSIC:
uri =
new Uri(
"/PresentationFramework.Classic, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/classic.xaml",
UriKind.Relative);
break;
//==================== ROYALE ======================================
//C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Royale.dll
//royale.normalcolor
case ThemeEnum.ROYALE:
uri =
new Uri(
"/PresentationFramework.Royale, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/royale.normalcolor.xaml",
UriKind.Relative);
break;
//==================== LUNA ======================================
//C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Luna.dll
//luna.normalcolor
case ThemeEnum.LUNA:
uri =
new Uri(
"/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/luna.normalcolor.xaml",
UriKind.Relative);
break;
//luna.homestead
case ThemeEnum.LUNA_HOMESTEAD:
uri =
new Uri(
"/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/luna.homestead.xaml",
UriKind.Relative);
break;
//luna.metallic
case ThemeEnum.LUNA_METALLIC:
uri =
new Uri(
"/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/luna.metallic.xaml",
UriKind.Relative);
break;
//==================== AERO ======================================
//C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Aero.dll
//aero.normalcolor
case ThemeEnum.AERO:
uri =
new Uri(
"/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml",
UriKind.Relative);
break;
}
return Application.LoadComponent(uri) as ResourceDictionary;
}
}
}
posted @ 2008-08-07 00:16 XMLSpy 阅读(2868) 评论(7)
编辑
需求:
/// 对同一个类型的两个序列(或叫集合,数组) users,users1进行比较,
/// users1中的元素如果users中没有,就把这些元素与users的元素组合.
解决方案:

Code
using System;
using System.Collections.Generic;
using System.Linq;


namespace XMLSpy.Linq
{

/**//// <summary>
/// 对同一个类型的两个序列(或叫集合,数组) users,users1进行比较,
/// users1中的元素如果users中没有,就把这些元素与users的元素组合.
/// Author : xmlspy.spring@gmail.com
/// </summary>

public class SetCompare
{

public SetCompare()
{
List<User> users = new List<User>()

{
new User(0),
new User(3),
new User(1),
new User(8)
};

List<User> users1 = new List<User>()

{
new User(0),
new User(1),
new User(3),
new User(5)
};

Console.WriteLine("------------方式1---------------");
//方式1:使用扩展方法,必须实现IEqualityComparer<T>接口
//users1中的元素如果users中没有,就把这些元素与users的元素组合.
List<User> users2 = users.Union(users1, new UserEqualityComparer()).ToList();


foreach (User u in users2)
{
Console.WriteLine(u.Id);
}


/**////// 重新初始化

users = new List<User>()
{
new User(0),new User(3),
new User(1),new User(8)
};


users1 = new List<User>()
{
new User(0),new User(1),
new User(3),new User(5)
};


Console.WriteLine("------------方式2---------------");
//方式2:使用Linq语句,不用实现IEqualityComparer<T>接口

//步骤1:查找出users1中有而users中没有的User序列
var users3 = from user1 in users1
let tem = from user in users select user.Id
where tem.Contains(user1.Id) == false
select user1;
//步骤2:添加步骤1的结果到users中
users.AddRange(users3);


foreach (User u in users)
{
Console.WriteLine(u.Id);
}
}
}


public class UserEqualityComparer : IEqualityComparer<User>
{

public bool Equals(User x, User y)
{
return x.Id == y.Id;
}


public int GetHashCode(User obj)
{
return obj.Id;
}
}


public class User
{
private int _id;
private string _name;


Constructors#region Constructors

public User(int id)
{
_id = id;
}
#endregion


Properties#region Properties

public int Id
{

get
{ return _id; }

set
{ _id = value; }
}

public string Name
{

get
{ return _name; }

set
{ _name = value; }
}
#endregion
}
}
posted @ 2008-08-06 23:50 XMLSpy 阅读(1037) 评论(13)
编辑
posted @ 2008-08-05 23:57 XMLSpy 阅读(1756) 评论(14)
编辑
posted @ 2008-08-05 23:55 XMLSpy 阅读(1123) 评论(6)
编辑
posted @ 2008-08-03 16:59 XMLSpy 阅读(827) 评论(0)
编辑