WPF XAML动画属性路径不工作
我正在尝试为metro样式按钮的内容设置动画。 我的问题是按钮的内容不会改变颜色。 前景色不变 以下是我的按钮样式:WPF XAML动画属性路径不工作,wpf,xaml,animation,properties,path,Wpf,Xaml,Animation,Properties,Path,我正在尝试为metro样式按钮的内容设置动画。 我的问题是按钮的内容不会改变颜色。 前景色不变 以下是我的按钮样式: <Style x:Key="MetroButtonStyle" TargetType="Button"> <Setter Property="MinWidth" Value="40"/> <Setter Property="Width" Value="100"/&g
<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"/>
您有
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="EllipseInnerContent"
在动画中,其中EllipseInnerContent
是一个ContentPresenter
,而ContentPresenter
上没有前台
属性
将其更改为ContentControl
此外,当将TextBlock
作为控件的内容时,它将继承它所属的page\user控件的前景。使用DataTemplate
为您创建TextBlock
,然后它将从按钮继承前景。您已经
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="EllipseInnerContent"
在动画中,其中EllipseInnerContent
是一个ContentPresenter
,而ContentPresenter
上没有前台
属性
将其更改为ContentControl
此外,当将
TextBlock
作为控件的内容时,它将继承它所属的page\user控件的前景。使用DataTemplate
为您创建TextBlock
,然后它将从按钮继承前景。TextBlock不是控件。TextBlock是一个框架元素。这就是为什么无法设置控件.前台属性的动画。将TargetProperty更改为Storyboard.TargetProperty=“(TextBlock.前台)。(SolidColorBrush.Color)”不会更改任何内容。它能工作吗?是一个类似的问题TextBlock不是控件。TextBlock是一个框架元素。这就是为什么无法设置控件.前台属性的动画。将TargetProperty更改为Storyboard.TargetProperty=“(TextBlock.前台)。(SolidColorBrush.Color)”不会更改任何内容。它能工作吗?这是一个类似的问题