wpf textblock 会覆盖 button里面字体样式的解决方法 还有button的style覆盖。。datepicker里面的按钮的style

。(button使用contont写的时候) 当。button使用 <button.content><textBlock/></button.content>依然会覆盖

 这段代码能消除全局textblock对button的影响

 <DataTemplate DataType="{x:Type System:String}">
        <TextBlock Text="{Binding}">
            <TextBlock.Resources>
                <Style TargetType="{x:Type TextBlock}"/>
            </TextBlock.Resources></TextBlock>
    </DataTemplate>
View Code

 

 

 button  style

<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>
View Code

textblock style

 <Style  TargetType="{x:Type TextBlock}">

        <Setter Property="Foreground" Value="Red"/>
    </Style>

 

这样。。button里面的字是蓝色。。textblock里面是红色

 

 

还有button的style覆盖。。datepicker里面的按钮的style

 

 

 

posted @ 2013-06-29 00:32  法的空间  阅读(1011)  评论(1编辑  收藏  举报