zoukankan      html  css  js  c++  java
  • WPF笔记(1.9 样式和控件模板)——Hello,WPF!

    资源的另一个用途是样式设置:

    <Window >
      
    <Window.Resources>
        
    <Style x:Key="myStyle" TargetType="{x:Type TextBlock}">
          
    <Setter Property="VerticalAlignment" Value="Center" />
          
    <Setter Property="FontWeight" Value="Bold" />
          
    <Setter Property="FontStyle" Value="Italic" />
        
    </Style>
      
    </Window.Resources>
      
    <DockPanel >
        
    <StackPanel >
          
    <TextBlock Style="{StaticResource myStyle}">Name: </TextBlock>
          
    <TextBox Text="{Binding Path=Name}" />
          
    <TextBlock Style="{StaticResource myStyle}">Nick: </TextBlock>
          
    <TextBox Text="{Binding Path=Nick}" />
        
    </StackPanel>
        
      
    </DockPanel>
    </Window>

    代码很容易懂,记住用Setter定义每一个样式,注意指定了x:Key,然后哪个控件需要应用样式,就在控件里面指定Style;如果不指定x:Key,则所有控件都使用这个样式(当然也不会给控件设置Style="{StaticResource myStyle}")。
  • 相关阅读:
    poj2728 Desert King
    bzoj4289 Tax
    洛谷P4141消失之物
    Code Forces 698A Vacations
    Code Forces 543A Writing Code
    洛谷P1133 教主的花园
    poj3177 Redundant Paths
    bzoj1151 动物园
    bzoj1503 郁闷的出纳员
    bzoj1208 宠物收养所
  • 原文地址:https://www.cnblogs.com/Jax/p/695633.html
Copyright © 2011-2022 走看看