【发布时间】:2009-11-26 18:10:34
【问题描述】:
我一直在尝试处理以下问题: 在 Expression Blend 3 中为不同的视觉状态创建自定义动画时,它会更改网格上多个元素的大小/不透明度,它会在网格本身而不是控件样式中创建视觉状态组,并将其定义为 CustomVisualStateManager。
<Grid x:Name="LayoutRoot" Background="White" Height="500" HorizontalAlignment="Left" VerticalAlignment="Top" Width="500">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="MyVisualStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.3000000">
<VisualTransition.GeneratedEasingFunction>
<CircleEase EasingMode="EaseIn"/>
</VisualTransition.GeneratedEasingFunction>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="State1"/>
<VisualState x:Name="State2">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="myBox" Storyboard.TargetProperty="(FrameworkElement.Height)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="360"/>
<!-- omitting other storyboard animations here for clarity -->
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<VisualStateManager.CustomVisualStateManager>
<ic:ExtendedVisualStateManager/>
</VisualStateManager.CustomVisualStateManager>
<!-- omitting other grid elements here for clarity -->
</Grid>
我没问题,但问题是,当我尝试时,我无法在代码隐藏中切换状态
VisualStateManager.GoToState(this, "State1", true);
什么都没有发生,因为控件本身没有定义这些视觉状态,如
所示VisualStateManager.GetVisualStateGroups(this);
如果我尝试
VisualStateManager.GetVisualStateGroups(LayoutRoot);
它准确地显示了我的需要。但是我不能将 LayoutRoot 传递给 VisualStateManager,因为它需要一个 Control 类型的参数,而 Grid 不是。 我的问题是 - 我如何在代码隐藏中访问/更改此 CustomVisualStateManager 的状态?
【问题讨论】:
标签: c# silverlight silverlight-3.0 expression-blend visualstatemanager