如何重置样式?

时间:2016-12-01 21:55:27

标签: c# wpf xaml

我有以下样式:

<Style TargetType="TextBlock">
   <Setter Property="Foreground" Value="Black" />
   <Setter Property="FontSize" Value="12" />
   <Setter Property="FontFamily" Value="Calibri" />
   <Setter Property="Height" Value="25" />
   <Setter Property="VerticalAlignment" Value="Top" />
   <Setter Property="HorizontalAlignment" Value="Right" />
   <Setter Property="Margin" Value="0,3,10,0" />   
</Style>
<Style BasedOn="{StaticResource {x:Static ToolBar.TextBoxStyleKey}}" TargetType="TextBox">
   <Setter Property="Foreground" Value="Black" />
   <Setter Property="FontSize" Value="15" />
   <Setter Property="FontFamily" Value="Calibri" />
   <Setter Property="Height" Value="25" />
   <Setter Property="HorizontalAlignment" Value="Stretch" />
   <Setter Property="VerticalAlignment" Value="Center" />
   <Setter Property="Margin" Value="0,0,4,4" />
   <!--<Setter Property="BorderBrush" Value="Blue"/>
   <Setter Property="BorderThickness" Value="1" />-->
</Style>
<Style TargetType="DatePicker">
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="FontSize" Value="15" />
    <Setter Property="FontFamily" Value="Calibri" />
    <Setter Property="Height" Value="50" />                               
    <Setter Property="HorizontalAlignment" Value="Stretch" />          
    <Setter Property="BorderBrush" Value="{x:Null}"/>           
 </Style>
<Style TargetType="DatePickerTextBox" BasedOn="{StaticResource {x:Static ToolBar.TextBoxStyleKey}}" >
   <Setter Property="Foreground" Value="Black" />
   <Setter Property="FontSize" Value="15" />
   <Setter Property="FontFamily" Value="Calibri" />
   <Setter Property="Height" Value="25" />
   <Setter Property="HorizontalAlignment" Value="Stretch" />            
   <Setter Property="Margin" Value="0,0,4,4" />
</Style>
<Style TargetType="CalendarItem">
   <Setter Property="Style" Value="{x:Null}"/>             
</Style>

现在文本块样式搞乱了日历,显示时,日期和月份名称都很大且部分可见。

我尝试使用以下方法重置日历样式:

<Style TargetType="CalendarItem">
   <Setter Property="Style" Value="{x:Null}"/>             
</Style>

但似乎日历上没有任何影响。我也试过targettype =“Calendar”,但没有影响。

如何将日历样式重置为默认样式?

2 个答案:

答案 0 :(得分:0)

为文本块样式指定一个键:

<Style TargetType="TextBlock" x:Key="tbCustomStyle">
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="FontFamily" Value="Calibri" />
            <Setter Property="Height" Value="25" />
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="Margin" Value="0,3,10,0" />   
</Style>

这样,日历就不会影响文本块的默认样式。

然后,当您想在xaml中应用此特定样式时,可以使用以下内容:

<TextBlock Style="{StaticResource tbCustomStyle}">

</TextBlock>

答案 1 :(得分:0)

尝试为此类型声明一个空样式:

<Style TargetType="{x:Type dg:Calendar}" x:Key="CalendarItem">
</Style>

如果这会重置样式,请告诉我。