wpf textblock 会覆盖 button里面字体样式的解决方法 还有button的style覆盖。。datepicker里面的按钮的style
。(button使用contont写的时候) 当。button使用 <button.content><textBlock/></button.content>依然会覆盖
这段代码能消除全局textblock对button的影响
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<DataTemplate DataType="{x:Type System:String}"> <TextBlock Text="{Binding}"> <TextBlock.Resources> <Style TargetType="{x:Type TextBlock}"/> </TextBlock.Resources></TextBlock> </DataTemplate>
button style
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<Style TargetType="Button"> <Setter Property="Foreground" Value="Blue"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border CornerRadius="5" BorderBrush="Black" BorderThickness="1"> <ContentPresenter Grid.Row="1" Margin="3"> <ContentPresenter.Resources> <Style TargetType="{x:Type TextBlock}"> <Setter Property="Foreground" Value="Blue"/> </Style> </ContentPresenter.Resources> </ContentPresenter> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
textblock style
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Red"/>
</Style>
这样。。button里面的字是蓝色。。textblock里面是红色
还有button的style覆盖。。datepicker里面的按钮的style