信息系统开发平台OpenExpressApp - 支持WPF主题样式

  OpenExpressApp中有一个项目【OpenExpressApp.Module.WPF.Style】,它作为以后UI样式扩展用,以前只是放在那里,其实没有做什么工作,主要也就是告诉大家后期会增加主题样式。前期做框架、做引擎时,由于侧重点不一样,所以有时经常被人说做出来的东西真丑:)所以最近就花了两天把样式扩展加进来了。目前主要从网上下载了微软的一些样式,还没有扩充OEA内部控件的样式,界面如下图:

ThemeManager

  在【OpenExpressApp.Module.WPF.Style】中有一个ThemeManager.cs单元,这是主题管理的唯一一个类,其余都是各个主题的样式文件。这些都是从网上下载的,由于比较简单,就不做具体介绍了,只把代码附上:

代码
public static class ThemeManager
{
public static ResourceDictionary GetThemeResourceDictionary(string theme)
{
if (theme != null)
{
// Assembly assembly = Assembly.LoadFrom("OpenExpressApp.Module.WPF.Style");
string packUri = String.Format(@"/OpenExpressApp.Module.WPF.Style;component/{0}/Theme.xaml", theme);
return Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary;
}
return null;
}

public static string[] GetThemes()
{
string[] themes = new string[]
{
"朴素","朦胧蓝","ExpressionDark", "ExpressionLight", "RainierOrange", "RainierPurple", "RainierRadialBlue",
"ShinyBlue", "ShinyRed", "ShinyDarkTeal", // "ShinyDarkGreen",
"ShinyDarkPurple",
"DavesGlossyControls", "WhistlerBlue", "BureauBlack", "BureauBlue", "BubbleCreme",
"UXMusingsRed", "UXMusingsGreen", "UXMusingsRoughRed", "UXMusingsRoughGreen", "UXMusingsBubblyBlue"
};
return themes;
}

public static void ApplyTheme(this Application app, string theme)
{
ResourceDictionary dictionary
= ThemeManager.GetThemeResourceDictionary(theme);

if (dictionary != null)
{
app.Resources.MergedDictionaries.Clear();
app.Resources.MergedDictionaries.Add(dictionary);
}
}

public static void ApplyTheme(this ContentControl control, string theme)
{
ResourceDictionary dictionary
= ThemeManager.GetThemeResourceDictionary(theme);

if (dictionary != null)
{
control.Resources.MergedDictionaries.Clear();
control.Resources.MergedDictionaries.Add(dictionary);
}
}

#region Theme

/// <summary>
/// Theme Attached Dependency Property
/// </summary>
public static readonly DependencyProperty ThemeProperty =
DependencyProperty.RegisterAttached(
"Theme", typeof(string), typeof(ThemeManager),
new FrameworkPropertyMetadata((string)string.Empty,
new PropertyChangedCallback(OnThemeChanged)));

/// <summary>
/// Gets the Theme property. This dependency property
/// indicates ....
/// </summary>
public static string GetTheme(DependencyObject d)
{
return (string)d.GetValue(ThemeProperty);
}

/// <summary>
/// Sets the Theme property. This dependency property
/// indicates ....
/// </summary>
public static void SetTheme(DependencyObject d, string value)
{
d.SetValue(ThemeProperty, value);
}

/// <summary>
/// Handles changes to the Theme property.
/// </summary>
private static void OnThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
string theme = e.NewValue as string;
if (theme == string.Empty)
return;

ContentControl control
= d as ContentControl;
if (control != null)
{
control.ApplyTheme(theme);
}
}

#endregion

 

 



posted on 2009-12-04 12:01 周 金根 阅读(1750) 评论(1) 编辑 收藏

评论

#1楼  回复 引用 查看   

沙发 哈哈 关注
2009-12-04 14:46 | 宁飞扬      

导航

公告

推荐:你可能需要的在线电子书 大家好,我叫周金根,现在在广联达任技术架构师,从事信息化管理软件相关产品开发近10年,关注敏捷个人、模型驱动软件工厂、产品管理。这三个方向分别对应着产品开发中的人员、技术和过程,是产品研发中三个热点,致力于通过OpenExpressApp 业务模型开发平台解决规模化产品开发问题。

抓虾
Google Reader
My Yahoo
有道
哪吒
鲜果
九点
QQ邮箱
昵称:周 金根
园龄:5年10个月
荣誉:推荐博客
粉丝:682
关注:27

常用链接

我的标签

随笔分类(631)

随笔档案(651)

同事

网站

最新评论

阅读排行榜

评论排行榜

推荐排行榜