首页 > 其他分享 >Styles 样式

Styles 样式

时间:2023-01-12 16:47:16浏览次数:32  
标签:Styles 样式 元素 命名 内联 属性

Inline Styles 内联样式

<Button  Margin="0,0,2,2" Grid.Row="0" Grid.Column="0"     
      Name="cell00" >
            <Button.Style>
                <Style>
                    <Setter Property="Button.FontSize" Value="32pt"/>
                    <Setter Property="Button.FontWeight" Value="Bold"/>
                </Style>
            </Button.Style>
</Button>
内联样式实际上涉及的输入不仅仅是设置属性,而且内联样式无法在元素之间共享。因此,内联样式的使用频率不如命名样式。 但是,如果您想向单个元素添加属性和数据触发器,则内联样式很有用

Named Styles  命名样式

 通过将相同的内联样式提升到资源中,我们可以授予它一个名称并在我们的按钮实例中按名称引用它

 <Window.Resources>
        <Style x:Key="CellTextStyle" >
            <Setter Property="Control.FontSize" Value="32pt"/>
            <Setter Property="Control.FontWeight" Value="Bold"/>
        </Style>
</Window.Resources>
<Button Style="{StaticResource CellTextStyle}"  Margin="2,0,2,2" Grid.Row="0" Grid.Column="1" Name="cell01" />

  

 

 

 

标签:Styles,样式,元素,命名,内联,属性
From: https://www.cnblogs.com/friend/p/17047041.html

相关文章