VisualState commonState不适用于xaml

时间:2015-10-02 17:06:29

标签: xaml win-universal-app visualstates uwp-xaml

我有这个XAML视图。视觉触发器的VisualStateGroups 工作正常,但普通州的VisualStateGroup没有。

我尝试在开头指定一个矩形然后都不起作用。在其他视图中,这工作正常.. :(

<view:NavigationStoredPage.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Styles/ResponsiveStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</view:NavigationStoredPage.Resources>
    <Grid>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="PointerOver">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="rer">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="#121212"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="MouseOver">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="rer">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="#121212"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups> 
        <Rectangle Fill="Red" x:Name="rer" Width="100" Height="100" HorizontalAlignment="Left" Canvas.ZIndex="99" VerticalAlignment="Top" />

1 个答案:

答案 0 :(得分:1)

您的代码实际上必须使用CommonStates转换为其中一个VisualStateManager.GoToState()才能转换状态。对于像Button这样的控件,它会自动发生,因为在Button类或其基类中的某个地方 - 会调用GoToState()