1

Windows Phone 8 프로젝트에서 작업하고 있습니다. 이 버튼의 문제점 :Button의 눌린 VisualState 애니메이션이 실행되지 않습니다.

 <Button x:Name="decreaseFontButton" Foreground="{StaticResource GlobalBrush}"> 
      <VisualStateManager.VisualStateGroups> 
       <VisualStateGroup x:Name="CommonStates"> 
        <VisualState x:Name="Pressed"> 
         <Storyboard> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Height" Storyboard.TargetName="decreaseFontButton"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="70"/> 
          </ObjectAnimationUsingKeyFrames> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="decreaseFontButton" Completed="ObjectAnimationUsingKeyFrames_Completed_1"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GlobalBrush}"/> 
          </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
        </VisualState> 
       </VisualStateGroup> 
      </VisualStateManager.VisualStateGroups> 
      <Button.Content> 
       <Image Source="/Assets/Player/sub_minus.png" Width="28" Height="28"/> 
      </Button.Content> 
     </Button> 

두 애니메이션 중 아무 것도 trigged되지 않는다는 것입니다. VisualStateGroup의 이름을 FocusState으로 변경하고 VisualState의 이름을 Focused으로 변경하려고 시도했지만 어떤 변경도 보지 못했습니다. 내가 뭘 잘못하고 있는지 말해 줄 수 있니?

감사합니다.

+1

당신이 그것을 호출하려는 얼마나 스토리 보드, 아무 문제가 없습니다. 제어 템플릿을 만들고 리소스를 선언해야합니다. 기본 단추 템플릿을 살펴보고 VisualStateManager를 사용하는 방법을 제안합니다. 답변을 공개하지 않으면 꽤 쉽게 누락 된 내용을 보여줄 수 있지만 멀리 떨어져있는 것은 아닙니다. –

+0

대단히 고맙습니다. 이미 해 보았습니다. 시각적 결과는 예상대로되었지만 초기 솔루션이 좋지 않은 이유를 아직 찾지 못했습니다. –

+1

그냥 VisualStateManager를 UIElement에 직접 적용 할 수 없기 때문에 UIElement TargetType의 컨트롤 템플릿에 있어야합니다. 별거 아니에요, 당신이 구제 수단을 찾았 기 때문에 기쁩니다. 환호 :) –

답변

1

문제는 어떻게 시각 상태를 수정하려고하는지에 있습니다. 이들은 실제로 버튼의 내부 템플릿의 일부이며 사용자가 시도하는 방식으로 구성 할 수 없습니다.

대신 원하는 시각적 상태 변경 사항이 포함 된 새 스타일을 만들고 단추에 스타일을 적용해야합니다. 이처럼

:

<phone:PhoneApplicationPage.Resources> 

    <SolidColorBrush Color="Aqua" x:Key="aquabrush" /> 

    <Style x:Key="AlternativeButtonStyle" TargetType="Button"> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/> 
     <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> 
     <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/> 
     <Setter Property="Padding" Value="10,5,10,6"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="Button"> 
        <Grid Background="Transparent"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"/> 
           <VisualState x:Name="MouseOver"/> 
           <VisualState x:Name="Pressed"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource aquabrush}"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Height" Storyboard.TargetName="ButtonBackground"> 
              <DiscreteObjectKeyFrame KeyTime="0" Value="70"/> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Disabled" /> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="FocusStates"/> 
         </VisualStateManager.VisualStateGroups> 
         <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}"> 
          <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</phone:PhoneApplicationPage.Resources> 

<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Button Content="pressed?" Style="{StaticResource AlternativeButtonStyle}" /> 
</Grid>