• 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>应该是无效,怎么还是有效呢?

  • 相关阅读:
    js获取当前时间日期
    js操作Cookie
    C#常用正则表达式
    jquery操作select、radio、checkbox表单元素
    js实现页面跳转的几种方式
    js获取页面宽高大小
    c++写一个类后编译发现class重定义
    vtkMultiThreader坑爹吗?
    vtkStandardNewMacro()出现错误的问题
    转:将CFormView嵌入到CDockablePane中
  • 原文地址:https://www.cnblogs.com/zhangtao/p/2347530.html
Copyright © 2020-2023  润新知