2017-08-15 53 views
0

我刚刚与VisualState合作,想知道如何将Storyboard.TargetName设置为正在设计的控件?VisualState Storyboard.TargetName在UWP

我希望下面的代码片段能让我的问题更清楚一点。

<Style x:Key="AppBarBtnStyle" TargetType="AppBarButton"> 

    <Setter Property="BorderBrush" Value="Gray"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="AppBarButton"> 
<Grid x:Name="Root" 
<VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Flash"> 
            <Storyboard> 
             <ColorAnimationUsingKeyFrames Storyboard.TargetName="WHAT GOES HERE TO TARGET THE BORDERBRUSH SET PREVIOUSLY ABOVE" Storyboard.TargetProperty="(BorderBrush).(SolidColorBrush.Color)" Duration="0:0:1"> 

回答

0

如何设置Storyboard.TargetName的控制正在被称呼?

看起来好像你想动画<Setter>哪个属性是BorderBrush。实际上,当使用样式来定义控件模板时,Style元素的TargetType和Control.Template设置器的ControlTemplate元素的TargetType应始终使用相同的值。详细信息请参考Setter class的样式和模板部分。

例如,BorderBrush属性,您可以在Grid控制其命名RootAppBarButton styles and templates里面找到它。

<Grid 
    x:Name="Root" 
    MinWidth="{TemplateBinding MinWidth}" 
    MaxWidth="{TemplateBinding MaxWidth}" 
    Background="{TemplateBinding Background}" 
    BorderBrush="{TemplateBinding BorderBrush}" 
    BorderThickness="{TemplateBinding BorderThickness}"> 

所以,你可以通过设置Storyboard.TargetNameRoot元素为这里的彩动画满足您的requierements。

<VisualState x:Name="Normal"> 
    <Storyboard> 
     <ColorAnimationUsingKeyFrames 
      Storyboard.TargetName="Root" 
      Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" 
      Duration="0:0:5"> 
      <LinearColorKeyFrame KeyTime="00:00:02" Value="Blue" /> 
      <DiscreteColorKeyFrame KeyTime="00:00:2.5" Value="Yellow" /> 
     </ColorAnimationUsingKeyFrames> 
     <PointerUpThemeAnimation Storyboard.TargetName="OverflowTextLabel" /> 
    </Storyboard> 
</VisualState>