更改情节提要

本文关键字: | 更新日期: 2023-09-27 18:32:03

我有一个问题:

我正在 Windows 8 中创建菜单幻灯片:

<Grid x:Name="grid" VerticalAlignment="Bottom" Margin="0,0,0,-500" Grid.RowSpan="2" Width="500" Height="500" Background="White" RenderTransformOrigin="0.5,0.5">
        <Grid.RenderTransform>
            <CompositeTransform/>
        </Grid.RenderTransform>
    </Grid>

我有这个动画:

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ShowHideHelp">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.2"/>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="HideHelp"/>
            <VisualState x:Name="ShowHelp">
                <Storyboard>
                    <DoubleAnimation Duration="0" To="-500" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

如何更改情节提要的 TO 属性 (To="-500")?(突出显示)

<Storyboard> <DoubleAnimation Duration="0" To="-500"....

更改情节提要

试试这个。

XAML

<Grid x:Name="grid" VerticalAlignment="Bottom" Margin="0,0,0,-500" Grid.RowSpan="2" Width="500" Height="500" Background="White" RenderTransformOrigin="0.5,0.5">
    <Grid.RenderTransform>
        <CompositeTransform/>
    </Grid.RenderTransform>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ShowHideHelp">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.2"/>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="HideHelp"/>
            <VisualState x:Name="ShowHelp">
                <Storyboard>
                    <DoubleAnimation Duration="0" To="-500" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>

C#

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var storyboard = VisualStateManager.GetVisualStateGroups(this.grid).Get("ShowHideHelp").States.Get("ShowHelp").Storyboard;
    ((DoubleAnimation)(storyboard.Children[0])).To = 500;
}
public static class VisualStateExtensions
{
    public static VisualStateGroup Get(this IList<VisualStateGroup> stateGroups, string name)
    {
        return stateGroups.Single(x => x.Name == name);
    }
    public static VisualState Get(this IList<VisualState> stateGroups, string name)
    {
        return stateGroups.Single(x => x.Name == name);
    }
}

这个对我有用,稍微改变了Xyroids代码:

var storyboard = ShowHelp.Storyboard;
((DoubleAnimation)(storyboard.Children[0])).To = 500;
相关文章:
  • 没有找到相关文章