码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 精修篇 样式继承

时间:2019-12-21 00:16:48      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:ica   min   white   data   wrap   href   一个   type   ati   

原文:WPF 精修篇 样式继承

 这个 是新知识 样式可以继承

 

技术图片

  1. <Style x:Key="TextBlockStyleBase" TargetType="{x:Type TextBlock}">
  2. <Setter Property="TextWrapping" Value="NoWrap"/>
  3. <Setter Property="TextTrimming" Value="None"/>
  4. <Setter Property="Background" Value="#FF666666"/>
  5. <Setter Property="Foreground" Value="White"/>
  6. </Style>
  7. <Style x:Key="TextBlockStyle1" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyleBase}">
  8. <Setter Property="Foreground" Value="Red"/>
  9. </Style>
  10. <Style x:Key="TextBlockStyle2" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyleBase}">
  11. <Setter Property="Background" Value="Brown"/>
  12. <Setter Property="Foreground" Value="Beige"/>
  13. </Style>
  14. </Window.Resources>
  15. <Grid>
  16. <TextBlock HorizontalAlignment="Left" Height="42" Margin="60.5,43,0,0" TextWrapping="Wrap" Text="TextBlockBase" VerticalAlignment="Top" Width="228" Style="{DynamicResource TextBlockStyleBase}"/>
  17. <TextBlock HorizontalAlignment="Left" Height="42" Margin="60,112,0,0" TextWrapping="Wrap" Text="TextBlock1" VerticalAlignment="Top" Width="228" Style="{DynamicResource TextBlockStyle1}"/>
  18. <TextBlock HorizontalAlignment="Left" Height="42" Margin="60,179,0,0" TextWrapping="Wrap" Text="TextBlock2" VerticalAlignment="Top" Width="228" Style="{DynamicResource TextBlockStyle2}"/>
  19. </Grid>

 

定义了一个主样式 俩个样 用 BasedOn 来继承 修改 或增加 显示不同的效果

WPF 精修篇 样式继承

标签:ica   min   white   data   wrap   href   一个   type   ati   

原文地址:https://www.cnblogs.com/lonelyxmas/p/12075465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!