zoukankan      html  css  js  c++  java
  • Windows Phone 7 cs页面添加样式

    对于控件的样式一般都是在xaml页面进行赋值的,不过有时候在一些特殊环境下,比如动态生成控件,那么这时候就是需要在cs页面上给控件添加样式了。

    第一种方法:

    现在App.xaml页面上把样式添加上为全局资源

    <Application.Resources>
            ……
    </Application.Resources>

    然后再其他cs页面通过下面的代码来赋值样式

    Style mystyle = Application.Current.Resources[styleName] as Style;

    Button bt = new Button();

    bt.Style = mystyle;

    第二种方法:

    直接在cs页面写样式的代码

    如:

    var style = new Style();
    style.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.Red)));
    style.Setters.Add(new Setter(ForegroundProperty, new SolidColorBrush(Colors.Blue)));
    var styleCopy = new Style();

    foreach (var setter in style.Setters)
    {
       var typedSetter = setter as Setter;
       if (typedSetter != null)
       {
         var newSetter = new Setter(typedSetter.Property, typedSetter.Value);
         styleCopy.Setters.Add(newSetter);
       }
    }

  • 相关阅读:
    ThreadPoolExecutor源码解析
    AQS框架
    (转)rvm安装与常用命令
    (转).gitignore详解
    (转)可简化iOS 应用程序开发的6个Xcode小技巧
    (转)webView清除缓存
    (转)git常见错误
    iOS本地通知
    (转)iOS获取设备型号
    (转)iOS平台UDID方案比较
  • 原文地址:https://www.cnblogs.com/linzheng/p/2341851.html
Copyright © 2011-2022 走看看