开发者

SIlverlight Generic Template Animat Parent Control Property

开发者 https://www.devze.com 2023-01-23 08:00 出处:网络
I have a custom control with its template defined in a generic.xaml.It is a two row grid in which the second row can be \"retracted into\" the first row.

I have a custom control with its template defined in a generic.xaml. It is a two row grid in which the second row can be "retracted into" the first row.

However, I found that when I simply animated the height of the second row or the grid to acheive the desired results,开发者_开发问答 the parent of the template (i.e the instance of my custom control) still had the same height. This lead to list boxes with lots of white space in them between each element.

I need to just have the animation change the height of the actual containing control, but I don't know how to do this. I can set the height easily with somthing like:

    <Style TargetType="myLib:MyControl">

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

However, when defining an animation, I have no idea what to put in the StoryBoard.TargetName to refer to "this" control:

  <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>

If I leave that blank I get an error.

I figure I can probably create the animation in the code behind for the control, but I'd like to use the state manager instead.

I also thought about creating a self referencing dependency property, that that seems a bit off course.

Isn't there some kind of binding I could use here?

Thanks in advance for any help :)

PS - I was able to later get the desired effect in code as such:

        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();

So I'm still hopeful that a similar markup solution can be done. Gads I'm sure its got to be something obvious I'm missing here.

0

精彩评论

暂无评论...
验证码 换一张
取 消