有的时候,可能会继承基础样式,利用BasedOn="{StaticResource {x:Type TextBlock}}"

有的时候,可能会继承基础样式,利用BasedOn="{StaticResource {x:Type TextBlock}}"

例如:

 1 <Window x:Class="Demo.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6         xmlns:local="clr-namespace:VideoAndAudioDemo"
 7         mc:Ignorable="d"
 8         Title="MainWindow" Height="450" Width="800">
 9     <Window.Resources>
10         <Style TargetType="TextBlock">
11             <Setter Property="Foreground" Value="Red" />
12         </Style>
13     </Window.Resources>
14     <Grid>        
15         <StackPanel>
16             <TextBlock Text="123">
17                 <TextBlock.Style>
18                     <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
19                         <Setter Property="FontSize" Value="18" />
20                     </Style>
21                 </TextBlock.Style>
22             </TextBlock>
23         </StackPanel>
24     </Grid>
25 </Window>

 

posted @ 2020-04-17 14:20  吃奶嘴的路飞  阅读(310)  评论(0编辑  收藏  举报