2
메트로 스타일 단추의 내용에 애니메이션을 적용하려고합니다. 내 문제는 단추의 내용이 색을 변경하지 않는다는 것입니다. 전경색이 변경되지 않습니다. 내가 그것을 사용하는 방법WPF XAML 애니메이션 속성 경로가 작동하지 않습니다.
<Style x:Key="MetroButtonStyle"
TargetType="Button">
<Setter Property="MinWidth"
Value="40"/>
<Setter Property="Width"
Value="100"/>
<Setter Property="MinHeight"
Value="88"/>
<Setter Property="HorizontalAlignment"
Value="Center"/>
<Setter Property="Foreground"
Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="AppButton"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0"
To="1"
Storyboard.TargetProperty="(UIElement.Opacity)"
Storyboard.TargetName="MouseOverEllipse"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Duration="0"
To="1"
Storyboard.TargetProperty="(UIElement.Opacity)"
Storyboard.TargetName="PressedEllipse"/>
<ColorAnimation Duration="0"
To="Black"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="EllipseInnerContent"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimation Duration="0"
To="#7F8D8D8D"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="EllipseInnerContent"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel Orientation="Vertical"
HorizontalAlignment="Center">
<Grid Margin="0,14,0,5"
HorizontalAlignment="Center"
MinWidth="40">
<Ellipse x:Name="PressedEllipse"
Fill="{TemplateBinding Foreground}"
Opacity="0"
Width="40"
Height="40"/>
<Ellipse x:Name="MouseOverEllipse"
Fill="#7F8D8D8D"
Opacity="0"
Width="40"
Height="40"/>
<Ellipse Fill="Transparent"
Stroke="{TemplateBinding Foreground}"
StrokeThickness="2"/>
<ContentPresenter x:Name="EllipseInnerContent"
Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
<TextBlock x:Name="LabelText"
TextWrapping="Wrap"
HorizontalAlignment="Center"
FontFamily="Segoe UI"
FontSize="12"
Text="{TemplateBinding Tag}"
Foreground="{TemplateBinding Foreground}"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
여기입니다 :
여기 내 버튼의 스타일입니다. 이없는 작품을 수행합니다
<Button Style="{StaticResource MetroButtonStyle}"
Tag="Blah">
<TextBlock Text="XXX"/>
</Button>
이 작동 :
<Button Style="{StaticResource MetroButtonStyle}"
Tag="Blah"
Content="XXX"/>
TextBlock이 컨트롤이 아닙니다. TextBlock은 FrameworkElement입니다. 이것이 Control.Foreground 속성의 애니메이션 효과가 작동하지 않는 이유입니다. – roberther
TargetProperty를 Storyboard.TargetProperty = "(TextBlock.Foreground). (SolidColorBrush.Color)"로 변경하면 아무 것도 변경되지 않습니다. 전혀 작동 할 수 있습니까? – SiriusNik
[여기] (http://stackoverflow.com/questions/3856780/in-a-buttons-control-template-how-can-i-set-the-color-of-contained-text)와 비슷한 질문입니다. – roberther