2012-05-26 23 views
12

Button Regular/DisabledJak mogę stylu Przyciski

Button Hover

Moja UX projektant przekazał mi te, i nie wiem od czego zacząć na stylizacji mojej aplikacji WPF. Każda pomoc będzie doceniona. Być może przykład dla jednego, który mogę przedłużyć dla dwóch pozostałych.

Będą to standardowe przyciski we wszystkich innych aspektach oprócz wyświetlacza. Nie sądzę, że muszę zaimplementować niestandardową kontrolę.

Odpowiedz

25

dokumentacji MSDN na Button Styles prawdopodobnie będzie pomocne dla Ciebie. Podaje przykład szablonu przycisku WPF, który powinien być w stanie edytować zgodnie z wymaganiami. Możesz umieścić Xaml w Windows.Resources, jeśli styl ma być używany tylko na tym formularzu, lub możesz edytować plik Application.xaml i umieścić informacje o stylu w sekcji Application.Resources, jeśli ma on być używany dla całego podanie.


Modified powyżej linku stylu, aby dać wam przykład:

<Application x:Class="Application" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
StartupUri="MainWindow.xaml"> 
    <Application.Resources> 
     <!--Control colors.--> 
     <Color x:Key="ControlNormalColor">#FFC0C0CE</Color> 
     <Color x:Key="ControlMouseOverColor">#FFAFA3B9</Color> 
     <Color x:Key="DisabledControlColor">#FFF2F2F2</Color> 
     <Color x:Key="DisabledForegroundColor">#FFBFBFBF</Color> 
     <Color x:Key="ControlPressedColor">#FF211AA9</Color> 

     <!-- FocusVisual --> 

     <Style x:Key="ButtonFocusVisual"> 
      <Setter Property="Control.Template"> 
       <Setter.Value> 
        <ControlTemplate> 
         <Border> 
          <Rectangle Margin="2" StrokeThickness="1" Stroke="#60000000" StrokeDashArray="1 2" /> 
         </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

     <!-- Button --> 
     <Style TargetType="Button"> 
      <Setter Property="SnapsToDevicePixels" Value="true" /> 
      <Setter Property="OverridesDefaultStyle" Value="true" /> 
      <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}" /> 
      <Setter Property="MinHeight" Value="29px" /> 
      <Setter Property="MinWidth" Value="103px" /> 
      <Setter Property="Foreground" Value="#FFFFFFFF" /> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="Button"> 
         <Border TextBlock.Foreground="{TemplateBinding Foreground}" x:Name="Border"> 
          <Border.Background> 
           <SolidColorBrush Color="{DynamicResource ControlNormalColor}" /> 
          </Border.Background> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup x:Name="CommonStates"> 
            <VisualStateGroup.Transitions> 
             <VisualTransition GeneratedDuration="0:0:0.5" /> 
             <VisualTransition GeneratedDuration="0" To="Pressed" /> 
            </VisualStateGroup.Transitions> 
            <VisualState x:Name="Normal" /> 
            <VisualState x:Name="MouseOver"> 
             <Storyboard> 
              <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" 
               Storyboard.TargetName="Border"> 
               <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlMouseOverColor}" /> 
              </ColorAnimationUsingKeyFrames> 
             </Storyboard> 
            </VisualState> 
            <VisualState x:Name="Pressed"> 
             <Storyboard> 
              <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" 
               Storyboard.TargetName="Border"> 
               <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColor}" /> 
              </ColorAnimationUsingKeyFrames> 
             </Storyboard> 
            </VisualState> 
            <VisualState x:Name="Disabled"> 
             <Storyboard> 
              <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" 
               Storyboard.TargetName="Border"> 
               <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlColor}" /> 
              </ColorAnimationUsingKeyFrames> 
              <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" 
               Storyboard.TargetName="Border"> 
               <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledForegroundColor}" /> 
              </ColorAnimationUsingKeyFrames> 
             </Storyboard> 
            </VisualState> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
          <ContentPresenter Margin="2" 
          HorizontalAlignment="Center" 
          VerticalAlignment="Center" 
          RecognizesAccessKey="True" /> 
         </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

    </Application.Resources> 
</Application> 
+0

Stosując to do ResourceDictionary wyniku w wierd zachowanie. Jeśli rolowałem na przycisku, wszystkie przyciski zmieniają kolor, jeśli kliknę jeden przycisk, wszystkie przyciski migają ... Czy brakuje mi czegoś ...? – dba

+0

@dba, nie widząc kodu, nie ma sposobu, aby powiedzieć. Lepiej będzie, jeśli zadasz nowe pytanie. –

+0

Znalazłem problem ... Od kiedy miałem już zdefiniowane pewne bryły Solidcolor, zmieniłem Backgroud Setter na Border na "Attribute-Style" ... Zły pomysł, jak się nauczyłem ...: D Twój kod działa: D – dba