WPF 精修篇 样式继承

原文: 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 来继承 修改 或增加 显示不同的效果

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/12075465.html