【问题标题】:Animate width WPF left sided动画宽度 WPF 左侧
【发布时间】:2014-09-03 14:10:45
【问题描述】:

我有一个Grid,我可以通过以下方式制作动画:

当我单击图像时,我可以使用 Storyboard 为按钮的模板设置动画,使其随心所欲地增长,结果如下:

这或多或少会是结果。动画是这样的:

 <Storyboard x:Key="ExpandPanelRight">
    <DoubleAnimation
        Storyboard.TargetName="ExpandablePanel"
        Storyboard.TargetProperty="Width"
        BeginTime="0:0:0"
        From="0" To="450" Duration="0:0:0.5"></DoubleAnimation>
</Storyboard>

如您所见,从左到右扩展网格没有问题,但我真正想要的是相反:从右到左扩展网格:

会怎么样??我找不到答案。

【问题讨论】:

  • 不要认为解决方案是在您的动画中,而是在您的网格布局中。某处 Horizo​​ntalAlignment="Right" 必须发挥作用。

标签: wpf xaml animation wpf-animation


【解决方案1】:

您需要做的就是将您的 bin Image 与您的 ExpandablePanel 的右边缘对齐。完成此操作后,Image 将随着PanelWidth 的增加而粘在右侧。您的 StoryboardDoubleAnimation 代码可以保持不变。您的代码应如下所示:

<Border CornerRadius="10" Background="Blue">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <TextBlock Text="Expanding...." VerticalAlignment="Center" />
        <Image Source="Images/Bin.png" VerticalAlignment="Center" HorizontalAlignment="Right" />
    </Grid>
</Border>

【讨论】:

  • 这可能是解决方案,但我的不是Expander,它是一个包含一些元素的网格...您建议使用Expanders 而不是Grid 吗?跨度>
  • 不需要使用Expander 控件。任何控件的Width 都可以设置动画。 如果您使用上述代码,您可以轻松地为Border.Width 设置动画。
  • 完美!就是这样!谢谢!!
猜你喜欢
  • 1970-01-01
  • 2012-07-30
  • 1970-01-01
  • 2020-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 2021-11-16
相关资源
最近更新 更多