2017-06-07 21 views
1

私はWPFが新しく、ボタンテンプレートのテキストとアイコンの色に変更したいと思います。しかし、私は不透明度を変更することしかできないようです。 私はボタンの子供たちにスタイルを適用する必要があると思うが、私はどのようにわからない。ここでボタンテンプレートの子にWPF stypeを適用する方法

はテンプレートです:あなたの助けのための

<Style x:Key="AppButton" TargetType="{x:Type Button}"> 

    <Setter Property="Opacity" Value="0.25" /> 
    <Setter Property="Foreground" Value="#FFFF9966" /> 

    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Trigger.EnterActions> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0:0.3" /> 
         <!--<ColorAnimation Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="Green" Duration="0:0:0:0.3" />--> 

         <ColorAnimationUsingKeyFrames Storyboard.Target="{Binding RelativeSource={RelativeSource TemplatedParent}}" 
                 Storyboard.TargetProperty="(TextBox.Foreground).(SolidColorBrush.Color)"> 
          <EasingColorKeyFrame KeyTime="0" Value="Green" /> 
         </ColorAnimationUsingKeyFrames> 

        </Storyboard> 
       </BeginStoryboard> 
      </Trigger.EnterActions> 
      <Trigger.ExitActions> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.25" Duration="0:0:0:0.3" /> 
         <!--<ColorAnimation Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="White" Duration="0:0:0:0.3" />--> 

         <ColorAnimationUsingKeyFrames Storyboard.Target="{Binding RelativeSource={RelativeSource TemplatedParent}}" 
                 Storyboard.TargetProperty="(TextBox.Foreground).(SolidColorBrush.Color)"> 
          <EasingColorKeyFrame KeyTime="0" Value="White" /> 
         </ColorAnimationUsingKeyFrames> 

        </Storyboard> 
       </BeginStoryboard> 
      </Trigger.ExitActions> 
     </Trigger> 
    </Style.Triggers> 

</Style> 

ありがとう:

<Button x:Name="btnApp1" Width="56" Height="66" Margin="0,0,0,0" Style="{StaticResource AppButton}"> 
     <Button.Template> 
      <ControlTemplate TargetType="Button"> 
       <Grid> 
        <iconPacks:PackIconMaterial Kind="StarOutline" Width="48" Height="48" VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="#FFFFFFFF" /> 
        <TextBlock x:Name="tButton" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="#FFFFFFFF" FontWeight="Bold">PVIE</TextBlock> 
       </Grid> 
      </ControlTemplate> 
     </Button.Template> 
    </Button> 

そして、ここでは、スタイルです。

+0

どういたしまして – Dams

答えて

1

バインド{TemplateBinding}を使用してTextBlockControlTemplateIconForegroundプロパティ:

<Button x:Name="btnApp1" Width="56" Height="66" Margin="0,0,0,0" Style="{StaticResource AppButton}"> 
    <Button.Template> 
     <ControlTemplate TargetType="Button"> 
      <Grid> 
       <iconPacks:PackIconMaterial Kind="StarOutline" Width="48" Height="48" VerticalAlignment="Top" HorizontalAlignment="Center" 
           Foreground="{TemplateBinding Foreground}" /> 
       <TextBlock x:Name="tButton" HorizontalAlignment="Center" VerticalAlignment="Bottom" 
          Foreground="{TemplateBinding Foreground}" FontWeight="Bold">PVIE</TextBlock> 
      </Grid> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 
+0

可能な場合、私は、両方を行うしたいと思います。有益な答えを投票することを忘れないでください:) https://stackoverflow.com/help/privileges/vote-up – mm8

+1

それは完了しました;-) – Dams

+1

いいえ:)あなたは答えを受け入れましたが、それをupvotedしていません。投稿の左にある大きな上向きの矢印をクリックすると、それをアップヴォートすることができます。 – mm8

関連する問題