2016-06-21 3 views
0

App.xaml에 선언 된 기본 단추 스타일이 있습니다. DropShadowEffect가 적용되었습니다. 이상한 것은 DropShadowEffect도 적용되고 있습니다 DatePicker 아무도 DatePicker에서 DropShadowEffect를 제거하는 방법을 도울 수 있습니까?DatePicker에 적용되는 단추 스타일

답변

3

DatePicker 컨트롤은 사용자가 정의한 표준 (기본) 단추 서식 파일을 사용하기 때문입니다. 내 모든 DatePickers의 모양을 엉망으로 만드는 내 기본 단추 스타일로 동일한 문제가 발생했습니다. 두 사람은이 문제를 해결하기위한 것이었다 있습니다

해결 방법 1 : (좋지 않은)

은 기본 스타일에 키를 추가하고 사용해야 앱에서 모든 버튼에 적용합니다. 이 솔루션은 제가 스타일을 기본값보다 우선적으로 사용하기를 원했기 때문에 제게는 의문의 여지가있었습니다. 그래서 ...

해결 방법 2 : (선호하지만 약간 고통스러운 방법)

재정의 컨트롤에 마우스 오른쪽 버튼으로 클릭하여 App.xaml (또는 Styles.xaml) 파일의 기본 버튼과 DatePicker에서의 스타일 XAML 디자이너 ->템플릿 편집 -> 복사본 편집 ... 새로 추가 된 단추 스타일에 DefaultWpfButtonStyle (기본값으로 사용되지 않도록 함)이라는 키를 추가 한 다음 스타일을 DatePicker 스타일/템플릿 내부의 Button 컨트롤에 추가합니다. 이렇게하면 DatePicker가 기본 스타일 대신 응용 프로그램의 드롭 다운 버튼에 기본 WPF 버튼 스타일을 사용하도록 할 수 있습니다.

<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/> 
    <SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/> 
    <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/> 
    <SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/> 
    <SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/> 
    <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/> 
    <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/> 
    <SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/> 
    <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/> 

    <Style x:Key="FocusVisual"> 
     <Setter Property="Control.Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

    <Style x:Key="defaultWPFButtonStyle" TargetType="{x:Type Button}"> 
     <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> 
     <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Padding" Value="1"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type Button}"> 
        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> 
         <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
        </Border> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsDefaulted" Value="true"> 
          <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> 
         </Trigger> 
         <Trigger Property="IsMouseOver" Value="true"> 
          <Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/> 
          <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/> 
         </Trigger> 
         <Trigger Property="IsPressed" Value="true"> 
          <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/> 
          <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/> 
         </Trigger> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/> 
          <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/> 
          <Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

    <Style TargetType="{x:Type DatePicker}"> 
     <Setter Property="Foreground" Value="#FF333333"/> 
     <Setter Property="IsTodayHighlighted" Value="True"/> 
     <Setter Property="SelectedDateFormat" Value="Short"/> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="Padding" Value="2"/> 
     <Setter Property="BorderBrush"> 
      <Setter.Value> 
       <LinearGradientBrush EndPoint=".5,0" StartPoint=".5,1"> 
        <GradientStop Color="#FFA3AEB9" Offset="0"/> 
        <GradientStop Color="#FF8399A9" Offset="0.375"/> 
        <GradientStop Color="#FF718597" Offset="0.375"/> 
        <GradientStop Color="#FF617584" Offset="1"/> 
       </LinearGradientBrush> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type DatePicker}"> 
        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"/> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> 
          <Grid.Resources> 
           <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/> 
           <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}"> 
            <Grid> 
             <VisualStateManager.VisualStateGroups> 
              <VisualStateGroup x:Name="CommonStates"> 
               <VisualStateGroup.Transitions> 
                <VisualTransition GeneratedDuration="0"/> 
                <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/> 
                <VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/> 
               </VisualStateGroup.Transitions> 
               <VisualState x:Name="Normal"/> 
               <VisualState x:Name="MouseOver"> 
                <Storyboard> 
                 <ColorAnimation Duration="0" To="#FF448DCA" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"/> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                </Storyboard> 
               </VisualState> 
               <VisualState x:Name="Pressed"> 
                <Storyboard> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#FF448DCA"/> 
                 </ColorAnimationUsingKeyFrames> 
                 <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight"> 
                  <SplineDoubleKeyFrame KeyTime="0" Value="1"/> 
                 </DoubleAnimationUsingKeyFrames> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#EAFFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#6BFFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                 <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"> 
                  <SplineColorKeyFrame KeyTime="0" Value="#F4FFFFFF"/> 
                 </ColorAnimationUsingKeyFrames> 
                </Storyboard> 
               </VisualState> 
               <VisualState x:Name="Disabled"/> 
              </VisualStateGroup> 
             </VisualStateManager.VisualStateGroups> 
             <Grid Background="#11FFFFFF" FlowDirection="LeftToRight" HorizontalAlignment="Center" Height="18" Margin="0" VerticalAlignment="Center" Width="19"> 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="20*"/> 
               <ColumnDefinition Width="20*"/> 
               <ColumnDefinition Width="20*"/> 
               <ColumnDefinition Width="20*"/> 
              </Grid.ColumnDefinitions> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="23*"/> 
               <RowDefinition Height="19*"/> 
               <RowDefinition Height="19*"/> 
               <RowDefinition Height="19*"/> 
              </Grid.RowDefinitions> 
              <Border x:Name="Highlight" BorderBrush="#FF45D6FA" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius="0,0,1,1" Margin="-1" Opacity="0" Grid.Row="0" Grid.RowSpan="4"/> 
              <Border x:Name="Background" BorderBrush="#FFFFFFFF" BorderThickness="1" Background="#FF1F3B53" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3"/> 
              <Border x:Name="BackgroundGradient" BorderBrush="#BF000000" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3"> 
               <Border.Background> 
                <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0"> 
                 <GradientStop Color="#FFFFFFFF" Offset="0"/> 
                 <GradientStop Color="#F9FFFFFF" Offset="0.375"/> 
                 <GradientStop Color="#E5FFFFFF" Offset="0.625"/> 
                 <GradientStop Color="#C6FFFFFF" Offset="1"/> 
                </LinearGradientBrush> 
               </Border.Background> 
              </Border> 
              <Rectangle Grid.ColumnSpan="4" Grid.RowSpan="1" StrokeThickness="1"> 
               <Rectangle.Fill> 
                <LinearGradientBrush EndPoint="0.3,-1.1" StartPoint="0.46,1.6"> 
                 <GradientStop Color="#FF4084BD"/> 
                 <GradientStop Color="#FFAFCFEA" Offset="1"/> 
                </LinearGradientBrush> 
               </Rectangle.Fill> 
               <Rectangle.Stroke> 
                <LinearGradientBrush EndPoint="0.48,-1" StartPoint="0.48,1.25"> 
                 <GradientStop Color="#FF494949"/> 
                 <GradientStop Color="#FF9F9F9F" Offset="1"/> 
                </LinearGradientBrush> 
               </Rectangle.Stroke> 
              </Rectangle> 
              <Path Grid.ColumnSpan="4" Grid.Column="0" Data="M11.426758,8.4305077 L11.749023,8.4305077 L11.749023,16.331387 L10.674805,16.331387 L10.674805,10.299648 L9.0742188,11.298672 L9.0742188,10.294277 C9.4788408,10.090176 9.9094238,9.8090878 10.365967,9.4510155 C10.82251,9.0929432 11.176106,8.7527733 11.426758,8.4305077 z M14.65086,8.4305077 L18.566387,8.4305077 L18.566387,9.3435936 L15.671368,9.3435936 L15.671368,11.255703 C15.936341,11.058764 16.27293,10.960293 16.681133,10.960293 C17.411602,10.960293 17.969301,11.178717 18.354229,11.615566 C18.739157,12.052416 18.931622,12.673672 18.931622,13.479336 C18.931622,15.452317 18.052553,16.438808 16.294415,16.438808 C15.560365,16.438808 14.951641,16.234707 14.468243,15.826504 L14.881817,14.929531 C15.368796,15.326992 15.837872,15.525723 16.289043,15.525723 C17.298809,15.525723 17.803692,14.895514 17.803692,13.635098 C17.803692,12.460618 17.305971,11.873379 16.310528,11.873379 C15.83071,11.873379 15.399232,12.079271 15.016094,12.491055 L14.65086,12.238613 z" Fill="#FF2F2F2F" HorizontalAlignment="Center" Margin="4,3,4,3" Grid.Row="1" Grid.RowSpan="3" RenderTransformOrigin="0.5,0.5" Stretch="Fill" VerticalAlignment="Center"/> 
              <Ellipse Grid.ColumnSpan="4" Fill="#FFFFFFFF" HorizontalAlignment="Center" Height="3" StrokeThickness="0" VerticalAlignment="Center" Width="3"/> 
              <Border x:Name="DisabledVisual" BorderBrush="#B2FFFFFF" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius="0,0,.5,.5" Opacity="0" Grid.Row="0" Grid.RowSpan="4"/> 
             </Grid> 
            </Grid> 
           </ControlTemplate> 
          </Grid.Resources> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*"/> 
           <ColumnDefinition Width="Auto"/> 
          </Grid.ColumnDefinitions> 
          <Button x:Name="PART_Button" Style="{StaticResource defaultWPFButtonStyle}" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="Left" Margin="0" Padding="0" Grid.Row="0" Template="{StaticResource DropDownButtonTemplate}" VerticalAlignment="Top" Width="20"/> 
          <DatePickerTextBox x:Name="PART_TextBox" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="Stretch" Grid.Row="0" VerticalContentAlignment="Stretch"/> 
          <Grid x:Name="PART_DisabledVisual" Grid.ColumnSpan="2" Grid.Column="0" IsHitTestVisible="False" Opacity="0" Grid.Row="0"> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="*"/> 
            <ColumnDefinition Width="Auto"/> 
           </Grid.ColumnDefinitions> 
           <Rectangle Grid.Column="0" Fill="#A5FFFFFF" RadiusY="1" Grid.Row="0" RadiusX="1"/> 
           <Rectangle Grid.Column="1" Fill="#A5FFFFFF" Height="18" Margin="3,0,3,0" RadiusY="1" Grid.Row="0" RadiusX="1" Width="19"/> 
           <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/> 
          </Grid> 
         </Grid> 
        </Border> 
        <ControlTemplate.Triggers> 
         <DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false"> 
          <Setter Property="Foreground" TargetName="PART_TextBox" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"/> 
         </DataTrigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

이제 기본 WPF 버튼 스타일을 사용하는 DatePickers을 제외하고 기본 스타일을 사용하여 응용 프로그램의 모든 버튼이 있어야합니다

가 아니면 그냥 다음 코드를 복사하여 붙여 넣을 수 있습니다.

+0

감사 : 여기

내 응용 프로그램 중 하나를위한 완벽한 App.xaml 파일입니다. 사용 된 두 번째 솔루션을 사용했습니다. 그것은 내가 원했던 조금 더 많은 코드이지만 지금은 작동합니다. – msnitin

0

이 문제를 해결하는 훨씬 간단한 방법이 있습니다. DatePicker 스타일의 스타일 설정 만 실행하면됩니다.

예를 들어 응용 프로그램의 모든 단추에 대한 기본 스타일을 정의하는 App.xaml이있는 경우 DatePicker 형식의 스타일을 만들고 스타일 리소스를 추가하여 단추 스타일을 취소하십시오.

<!-- Default style for all Buttons in the application --> 
<Style TargetType="{x:Type Button}"> 
    <Setter Property="MinHeight" Value="25" /> 
    <Setter Property="MinWidth" Value="85" /> 
</Style> 

<!-- Default style for all DatePicker in the application --> 
<Style TargetType="{x:Type DatePicker}"> 
    <Style.Resources> 
     <!-- Reset the Button style inside the DatePicker to default values --> 
     <Style TargetType="{x:Type Button}"> 
      <Setter Property="MinHeight" Value="0" /> 
      <Setter Property="MinWidth" Value="0" /> 
     </Style> 
    </Style.Resources> 
</Style> 

그래서 당신이 버튼이 어떤 특성 세터, 단지 그들을 취소하고 DatePicker에서 Style.Resource에 기본값을 설정합니다. 답에 대한

<Application x:Class="App1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:App1" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
    <ResourceDictionary> 

     <!-- Default style settings for all controls --> 
     <Style TargetType="{x:Type Control}" x:Key="BaseStyle"> 
      <Setter Property="HorizontalAlignment" Value="Left" /> 
      <Setter Property="VerticalAlignment" Value="Top" /> 
     </Style> 


     <!-- Default style for all Labels in the application --> 
     <Style TargetType="{x:Type Label}" BasedOn="{StaticResource BaseStyle}" /> 

     <!-- Default style for all Buttons in the application --> 
     <Style TargetType="{x:Type Button}" BasedOn="{StaticResource BaseStyle}"> 
      <Setter Property="MinHeight" Value="25" /> 
      <Setter Property="MinWidth" Value="85" /> 
     </Style> 

     <!-- Default style for all GroupBoxes in the application --> 
     <Style TargetType="{x:Type GroupBox}" BasedOn="{StaticResource BaseStyle}" /> 

     <!-- Default style for all CheckBoxes in the application --> 
     <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource BaseStyle}" /> 

     <!-- Default style for all ComboBoxes in the application --> 
     <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource BaseStyle}"> 
      <Setter Property="MinHeight" Value="25" /> 
      <Setter Property="MinWidth" Value="80" /> 
     </Style> 

     <!-- Default style for all TextBoxes in the application --> 
     <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource BaseStyle}"> 
      <Setter Property="MinHeight" Value="25" /> 
      <Setter Property="VerticalContentAlignment" Value="Center" /> 
     </Style> 

     <!-- Default style for all DatePicker in the application --> 
     <Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource BaseStyle}"> 
      <Style.Resources> 
       <!-- Reset the Button style inside the DatePicker to default values --> 
       <Style TargetType="{x:Type Button}"> 
        <Setter Property="HorizontalAlignment" Value="Stretch" /> 
        <Setter Property="VerticalAlignment" Value="Stretch" /> 
        <Setter Property="MinHeight" Value="0" /> 
        <Setter Property="MinWidth" Value="0" /> 
       </Style> 
      </Style.Resources> 
     </Style> 


    </ResourceDictionary> 
</Application.Resources> 

관련 문제