SIlverlight 通用模板 Animat 父控件属性
我有一个自定义控件,其模板在 generic.xaml 中定义。它是一个两行网格,其中第二行可以“缩回”第一行。
但是,我发现当我简单地对第二行或网格的高度进行动画处理以达到所需的结果时,模板的父级(即我的自定义控件的实例)仍然具有相同的高度。这会导致列表框的每个元素之间有大量空白。
我只需要让动画改变实际包含控件的高度,但我不知道该怎么做。我可以使用以下内容轻松设置高度:
<Style TargetType="myLib:MyControl">
<!--Default Values-->
<Setter Property="Height" Value="100" />
但是,在定义动画时,我不知道在 StoryBoard.TargetName 中放置什么来引用“此”控件:
<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();
所以我仍然希望可以完成类似的标记解决方案。我确信我在这里错过了一些明显的东西。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论