zoukankan      html  css  js  c++  java
  • wpf 样式问题

    今天看书时发现一个问题,觉得有点意思就做了一个demo:

     <Window.Resources>
    <Style x:Key="BigFontButtonStyle">
    <Setter Property="Control.FontFamily" Value="Times New Roman"></Setter>
    <Setter Property="Control.FontSize" Value="18"></Setter>
    <Setter Property="Control.FontWeight" Value="Bold"></Setter>
    </Style>

    <Style x:Key="ButtonStyle">
    <Setter Property="Button.FontFamily" Value="Times New Roman"></Setter>
    <Setter Property="Button.FontSize" Value="18"></Setter>
    <Setter Property="Button.FontWeight" Value="Bold"></Setter>
    </Style>

    <Style x:Key="TargetTypeStyle" TargetType="Button">
    <Setter Property="Button.FontFamily" Value="Times New Roman"></Setter>
    <Setter Property="Button.FontSize" Value="18"></Setter>
    <Setter Property="Button.FontWeight" Value="Bold"></Setter>
    </Style>
    </Window.Resources>

    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition />
    <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition />
    <RowDefinition />
    <RowDefinition />
    </Grid.RowDefinitions>
    <Button Content="Control.FontWeight" HorizontalAlignment="Center" Name="button1"
    VerticalAlignment
    ="Center" Style="{StaticResource BigFontButtonStyle}" />
    <TextBox Grid.Column="1" HorizontalAlignment="Center" Name="textBox1"
    VerticalAlignment
    ="Center" Style="{StaticResource BigFontButtonStyle}" Text="样式有效" />
    <Button Content="Button.FontWeight" Grid.Row="1" HorizontalAlignment="Center" Name="button2"
    VerticalAlignment
    ="Center" Style="{StaticResource ButtonStyle}" />
    <TextBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" Name="textBox2"
    VerticalAlignment
    ="Center" Style="{StaticResource ButtonStyle}" Text="样式无效"/>
    <Button Content="TargetTypeStyle" Grid.Row="2" HorizontalAlignment="Center" Name="button3"
    VerticalAlignment
    ="Center" Style="{StaticResource TargetTypeStyle}" />
    <TextBox Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" Name="textBox3"
    VerticalAlignment
    ="Center" Text="没有效果" />
    </Grid>

    如图效果:

    第二排textbox设置的是button的样式: <Style x:Key="ButtonStyle">
    <Setter Property="Button.FontFamily" Value="Times New Roman"></Setter>
    <Setter Property="Button.FontSize" Value="18"></Setter>
    <Setter Property="Button.FontWeight" Value="Bold"></Setter>
    </Style>应该是无效,怎么还是有效呢?

    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    solidworks中的一些标注尺寸的技巧
    SolidWorks 2-8草图绘制的一般过程
    SolidWorks 2-7 草图的约束【课程来自虎课网】
    SolidWorks 2-5 草图的编辑
    HTML 文本格式化实例--实体
    今天长进之redis的学习
    初步了解Quartz
    职场风云3
    内网穿透
    职场风云2
  • 原文地址:https://www.cnblogs.com/wpf123/p/2113895.html
Copyright © 2011-2022 走看看