SIlverlight通用模板Animat父控件属性

时间:2010-11-02 15:14:54

标签: silverlight animation custom-controls generics parent

我有一个自定义控件,其模板在generic.xaml中定义。它是一个双行网格,其中第二行可以“缩回”第一行。

但是,我发现当我简单地为第二行或网格的高度设置动画以实现所需的结果时,模板的父级(即我的自定义控件的实例)仍然具有相同的高度。这导致列表框在每个元素之间有很多空白区域。

我需要让动画改变实际包含控件的高度,但我不知道如何做到这一点。我可以通过以下方式轻松设置高度:

    <Style TargetType="myLib:MyControl">

      <!--Default Values-->
      <Setter Property="Height" Value="100" />

但是,在定义动画时,我不知道将什么放在StoryBoard.TargetName中来引用“this”控件:

  <VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="ViewStates">
      <VisualState x:Name="Retracted">
        <DoubleAnimation Storyboard.TargetName="this?" Storyboard.TargetProperty="Height" To="25" Duration="0" />
      </VisualState>
    </VisualStateGroup>
  </VisualStateManager.VisualStateGroups>

如果我留空,我会收到错误。

我想我可以在控件背后的代码中创建动画,但我想改用状态管理器。

我还考虑过创建一个自引用依赖属性,这似乎有点偏离。

我可以在这里使用某种绑定吗?

提前感谢您的任何帮助:)

PS - 我之后能够在代码中获得所需的效果:

        Storyboard sb = new Storyboard();
        DoubleAnimation da = new DoubleAnimation();
        da.To = ExtendedHeight;
        da.Duration = new Duration(TimeSpan.FromMilliseconds(200));
        sb.Children.Add(da);
        Storyboard.SetTarget(da, this);
        Storyboard.SetTargetProperty(da, new PropertyPath("Height"));
        sb.Begin();

所以我仍然希望能够完成类似的标记解决方案。 Gads我确信它必须是我在这里失踪的明显事物。

0 个答案:

没有答案
相关问题