现在,除了默认的Button模版不依赖于Foreground 和 Background 之外,活干的差不多了。
它可以使用更多的颜色和一个BorderBrush,但也有一些颜色在Button的属性上是无效的。具我所知也就能修改这两种属性.
我需要另外一个Button版本,其使用Foreground, Background 和 BorderBrush. 那我要如何组合这个style呢?
我想到可以使用BasedOn style,其XAML如下;
<UserControl.Resources>
<local:MySystemStyles
x:Key="mySystemStyles" />
<Style
x:Key="buttonStyle"
BasedOn="{Binding Source={StaticResource mySystemStyles},Path=ButtonStyle}">
在运行时无法工作( BasedOn 绑定时IE报错).
也许可以变换一下思路,当它在运行时创建一个style时,我可以通知 MySystemStyles 类。它应该基于当前的style。看起来有些麻烦但却可行;
public class MySystemStyles
{
public Style BasedOnButtonStyle
{
get
{
return (basedOnButtonStyle);
}
set
{
basedOnButtonStyle = value;
}
}
public Style ButtonStyle
{
get
{
if (buttonStyle == null)
{
buttonStyle = MakeStyle(typeof(Button), basedOnButtonStyle, buttonPropertyValues);
}
return (buttonStyle);
}
}
static Style MakeStyle(Type t, Style basedOnStyle, Dictionary<DependencyProperty, object> propertyValues)
{
Style style = new Style(t);
style.BasedOn = basedOnStyle;
foreach (var item in propertyValues)
{
style.Setters.Add(new Setter(item.Key, item.Value));
}
return (style);
}
static Dictionary<DependencyProperty, object> buttonPropertyValues =
new Dictionary<DependencyProperty, object>()
{
{ Control.ForegroundProperty, new SolidColorBrush(SystemColors.ControlTextColor) },
{ Control.BackgroundProperty, new SolidColorBrush(SystemColors.ControlColor) },
{ Button.BorderBrushProperty, new SolidColorBrush(SystemColors.ActiveBorderColor) }
};
Style buttonStyle;
Style basedOnButtonStyle;
}
评论加载中...- 2009-5-11Silverlight开发实践--PicZoomShow
- 2009-5-8快速浏览Silverlight3 Beta: SystemColor(系统颜色)
- 2009-5-6快速浏览Silverlight3 Beta:在线与离线状态检测
- 2009-5-6基于flex4技术从零开发flex博客系统: 8 using jsp and jstl
- 2009-5-6基于flex4技术从零开发flex博客系统: 7 Using JPA
- 2009-5-6基于flex4技术从零开发flex博客系统: 6 Using FluorineFx
- 2009-5-6基于flex4技术从零开发flex博客系统 : 5 数据存储之管理Greeting
- 2009-5-6基于flex4技术从零开发flex博客系统 : 4 数据存储
- 2009-5-6FMS3系列(六):使用远程共享对象实现多人实时在线聊天
- 2009-5-6使用silverlight构建一个工作流设计器(七)
