VisualState.Storyboard 属性

定义

获取或设置一个 情节提要,该情节提要 定义控件使用此视觉状态时的特定于状态的属性值和外观。

public:
 property Storyboard ^ Storyboard { Storyboard ^ get(); void set(Storyboard ^ value); };
Storyboard Storyboard();

void Storyboard(Storyboard value);
public Storyboard Storyboard { get; set; }
var storyboard = visualState.storyboard;
visualState.storyboard = storyboard;
Public Property Storyboard As Storyboard
<VisualState>
  singleStoryboard
</VisualState>

属性值

一个 情节提要,该情节提要 定义当此 VisualState 用作当前视觉状态时应用于控件的属性更改。

示例

此示例为包含一个 Grid按钮创建一个简单的 ControlTemplate。 x:Name 属性值为“PointerOver”的 VisualState 具有一个情节提要,当用户将指针放在 Button 上时,该情节提要 (Grid) 从绿色更改为红色。 包含 x:Name 属性值为“Normal”的 VisualState,以便当用户将指针从按钮上移开时,Grid 背景将返回到绿色。

<ControlTemplate TargetType="Button">
  <Grid >
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">

        <VisualStateGroup.Transitions>

          <!--Take one half second to transition to the PointerOver state.-->
          <VisualTransition To="PointerOver" 
                              GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>
        
        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            Pointer is over the button.-->
        <VisualState x:Name="PointerOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                            Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
</ControlTemplate>

注解

Storyboard 属性的值为 null 或单个 Storyboard 对象。 情节提要类似于动画的容器;它可以包含一个或多个动画定义。 每个此类动画都可以以特定命名目标上的特定依赖属性为目标。 命名目标必须是控件模板中的元素,该元素具有模板本身中定义的 Namex:Name 属性值 。 依赖属性必须是存在于该对象的对象模型中的属性或附加属性。 若要以动画为目标,请使用 Storyboard.TargetNameStoryboard.TargetProperty 附加属性。 有关如何使用 XAML 语法定义动画以及可以使用的动画类型的详细信息,请参阅 情节提要动画

影响布局的动画是潜在的依赖动画,在控件加载 VisualState 时,这可能会对控件的用户产生性能影响。 有关详细信息,请参阅视觉状态的情节提要动画

适用于

另请参阅