zoukankan      html  css  js  c++  java
  • 【silverlight】应用Style

    cmd.Style = (Style)this.Resources[ "AlternateBigButtonStyle"];
    
    后台设置style,来源于其他资源文件 ResourceDictionary resourceDictionary
    = new ResourceDictionary(); resourceDictionary.Source = new Uri("/Styles/AlternateStyles.xaml", UriKind.Relative); Style newStyle = (Style)resourceDictionary[ "BigButtonStyle"]; cmd.Style = newStyle;


    style继承:

    UserControl.Resources>
     <Style x: Key="BigButtonStyle" TargetType="Button">
     <Setter Property="FontFamily" Value="Georgia" />
     <Setter Property="FontSize" Value="40" />
     <Setter Property="Padding" Value="20" />
     <Setter Property="Margin" Value="10" />
     </Style>
     <Style x: Key="EmphasizedBigButtonStyle" TargetType="Button"
     BasedOn="{StaticResource BigButtonStyle}">
     <Setter Property="BorderBrush" Value="Black" />
     <Setter Property="BorderThickness" Value="5" />
     </Style>
    </UserControl.Resources>

    Automatically Applying Styles by Type<UserControl.Resources>

     <Style TargetType="Button">
     <Setter Property="FontFamily" Value="Georgia" />
     <Setter Property="FontSize" Value="40" />
     <Setter Property="Foreground" Value="SlateGray" />
     <Setter Property="Padding" Value="20" />
     <Setter Property="Margin" Value="10" />
    CHAPTER 14   STYLES AND BEHAVIORS
    519
     </Style>
    </UserControl.Resources>
    <StackPanel x: Name="LayoutRoot" Background="White">
     <Button Content="A Customized Button"></Button>
     <Button Content="Another Customized Button"></Button>
    </StackPanel>

    //Prevent Using A style
    <Button Content="A Non-Customized Button" Style="{x:Null}"></Button>

    Style Binding Expressions

    <UserControl.Resources>
     <FontFamily x: Key="buttonFontFamily">Georgia</FontFamily>
     <sys: Double x: Key="buttonFontSize">18</sys: Double>
     <FontWeight x: Key="buttonFontWeight">Bold</FontWeight>
     <Style x: Key="BigButtonStyle1" TargetType="Button">
     <Setter Property="FontFamily" Value="{StaticResource buttonFontFamily}" />
     <Setter Property="FontSize" Value="{StaticResource buttonFontSize}" />
     <Setter Property="FontWeight" Value="{StaticResource buttonFontWeight}" />
     </Style>

    binding后台一个类设置style

    public class FontInfo
    {
     public FontFamily FontFamily { get; set; }
     public double FontSize { get; set; }
     public FontWeight FontWeight { get; set; }
    }
    
    And if you make that namespace available to your markup:
    
    <UserControl xmlns: local="clr-namespace:Styles" ... >
    
    you can use it in your resources collection and bind to it in your styles:
    
    <UserControl.Resources>
     <local: FontInfo x: Key="buttonFont" FontFamily="Georgia" FontSize="18"
     FontWeight="Bold"></local: FontInfo>
     <Style x: Key="BigButtonStyle2" TargetType="Button">
     <Setter Property="Padding" Value="20" />
     <Setter Property="Margin" Value="10" />
     <Setter Property="FontFamily"
     Value="{Binding Source={StaticResource buttonFont}, Path=FontFamily}" />
     <Setter Property="FontSize"
     Value="{Binding Source={StaticResource buttonFont}, Path=FontSize}" />
     <Setter Property="FontWeight"
     Value="{Binding Source={StaticResource buttonFont}, Path=FontWeight}" />
     </Style>
    </UserControl.Resources>



  • 相关阅读:
    UVA 1386
    疯狂Android演讲2 环境配置
    七内部排序算法汇总(插入排序、Shell排序、冒泡排序、请选择类别、、高速分拣合并排序、堆排序)
    【iOS发展-44】通过案例谈iOS重构:合并、格式化输出、宏观变量、使用数组来存储数据字典,而且使用plist最终的知识
    jQuery选择
    一个月操作总结
    C++易vector
    oracle rac 在完成安装错误。
    NginX issues HTTP 499 error after 60 seconds despite config. (PHP and AWS)
    解决Eclipse中文乱码的方法
  • 原文地址:https://www.cnblogs.com/xlyg-14/p/4854652.html
Copyright © 2011-2022 走看看