Windows runtime 为什么经理不工作?

Windows runtime 为什么经理不工作?,windows-runtime,winrt-xaml,Windows Runtime,Winrt Xaml,下面是一个用户控件: <Grid x:Name="LayoutRoot"> <Border x:Name="Border1" Background="Green"> <TextBlock Text="Hello, World!"></TextBlock> </Border> </Grid> <VisualStateManager.VisualStateGroups> &l

下面是一个用户控件:

<Grid x:Name="LayoutRoot">
    <Border x:Name="Border1" Background="Green">
        <TextBlock Text="Hello, World!"></TextBlock>
    </Border>
</Grid>

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup >
        <VisualState x:Name="ExampleState">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Border1">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Red">
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

请你解释一下,为什么Border1不把它的颜色改成红色

是的,VSM应该在一个网格中,现在一切都可以工作了。

我遇到了同样的问题,并在官方文件的帮助下解决了这个问题:

我要从文件中挑选一句话:

控件作者或应用程序开发人员添加VisualStateGroup对象元素 到XAML中控件模板定义的根元素,使用 VisualStateManager.VisualStateGroups附加属性


因此,我认为导致VisualStateManager无法工作的原因是,VisualStateManager的部分应该放在hero元素(我想页面除外)范围内(可能是Grid,也可能是RelativePanel或其他)

将VSM放在边界上方的网格内,并使用
彩色动画
而不是使用关键帧的
对象动画
    public DialerView()
    {
        this.InitializeComponent();
        //LayoutRoot.DataContext = this;

        VisualStateManager.GoToState(this, "ExampleState", false);
    }