【发布时间】:2019-02-11 16:56:57
【问题描述】:
在 UWP 中,我实现了 ToggleButton 的视觉状态,尝试为其子控件的高度和前景等设置动画,但只有一种颜色动画有效,其余的并没有按预期更改值。但是,如果我将这些动画重写为设置器,它们就起作用了。我很确定我没有输入错误的值,否则会引发错误。这个 controlTemplate 也是扩展器的 headerStyle 模板的内容。
<ControlTemplate TargetType="ToggleButton">
<Grid
x:Name="ToggleButton"
Margin="0,0"
Padding="0"
Background="Transparent"
BorderBrush="{StaticResource mediumText}"
BorderThickness="1"
CornerRadius="5">
<RelativePanel x:Name="InnerExpanderRelativePanel" Margin="0">
<RelativePanel.Background>
<SolidColorBrush x:Name="InnerExpanderRelativePanelColor" Color="White" />
</RelativePanel.Background>
<RelativePanel Background="Transparent" RelativePanel.AlignVerticalCenterWithPanel="True">
<BitmapIcon
x:Name="OldApprovalIcon"
Width="30"
Height="30"
Margin="20,0,0,0"
RelativePanel.AlignLeftWithPanel="True"
UriSource="{StaticResource drawable/approval_detail_expired}">
<BitmapIcon.Foreground>
<SolidColorBrush
x:Name="IconColor"
Opacity="0.5"
Color="White" />
</BitmapIcon.Foreground>
</BitmapIcon>
<BitmapIcon
x:Name="OldApprovalIcon2"
Width="30"
Height="30"
Margin="20,0,0,0"
Opacity="0.5"
RelativePanel.AlignHorizontalCenterWith="OldApprovalIcon"
RelativePanel.AlignVerticalCenterWith="OldApprovalIcon"
UriSource="{StaticResource drawable/approval_detail_expired}">
<BitmapIcon.Foreground>
<SolidColorBrush
x:Name="IconColor2"
Opacity="0.5"
Color="{StaticResource rsvpRed}" />
</BitmapIcon.Foreground>
</BitmapIcon>
<TextBlock
Margin="20,0,0,0"
FontSize="15"
FontWeight="Medium"
Foreground="{StaticResource rsvpRed}"
RelativePanel.AlignVerticalCenterWithPanel="True"
RelativePanel.RightOf="OldApprovalIcon"
Text="show 29 expired eSignatures" />
</RelativePanel>
</RelativePanel>
<!-- animate expander header -->
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Target="IconColor.Color" Value="Black" />
<Setter Target="ToggleButton.Margin" Value="7" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Checked">
<VisualState.Setters>
<Setter Target="ToggleButton.Margin" Value="0" />
</VisualState.Setters>
<Storyboard>
<!--ONLY THIS WORKS-->
<ColorAnimation
Storyboard.TargetName="InnerExpanderRelativePanel"
Storyboard.TargetProperty="(RelativePanel.Background).(SolidColorBrush.Color)"
To="{StaticResource rsvpRed}"
Duration="0:0:0.2" />
<!--THESE THREE DON'T WORK-->
<DoubleAnimation
Storyboard.TargetName="InnerExpanderRelativePanel"
Storyboard.TargetProperty="Height"
To="50"
Duration="0:0:0.2" />
<ColorAnimation
Storyboard.TargetName="IconColor"
Storyboard.TargetProperty="Color"
To="White"
Duration="0:0:0.2" />
<ColorAnimation
Storyboard.TargetName="OldApprovalIcon2"
Storyboard.TargetProperty="(BitmapIcon.Foreground).(SolidColorBrush.Color)"
To="White"
Duration="0:0:0.2" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
【问题讨论】:
-
您的问题解决了吗?