4
속성을 변경하기위한 내 코드가 작동하지 않아 문제가 무엇인지 전혀 알 수 없지만 어쩌면 그렇게 할 수 있습니다.VisualStateManager를 올바르게 사용하려면 어떻게해야합니까?
다음은 오류를 재현하는 내 코드의 간단한 예입니다. 이 내 XAML 코드입니다 : 이것은 코드 숨김입니다
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="MyButton"
Height="100"
Width="300"
Content="Click"
FontSize="40"
FontWeight="Bold"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Background="Red" Click="MyButton_Click"/>
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Blue">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyButton"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="Aqua"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
: 그것을 클릭하면
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void MyButton_Click(object sender, RoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Blue", true);
}
}
은 이론적으로,이 버튼 색을 "아쿠아"로 변경해야하지만, 아무 반응이 없습니다 .