在我的网格控件上找不到VisualStateGroups

时间:2017-01-09 15:46:33

标签: c# uwp

我已将Windows Phone 8.1移植到UWP。我需要解决的最后一个难题就是这个问题:

我有一个包含Datatemplate的HubSection,它包含一个VisualStateManager和一系列网格。

<HubSection Name="hsBoardPassenger"  DataContext="{Binding Path=DataContext, ElementName=rootPage}">
                <DataTemplate>
                    <Grid x:Name="grdBoardPassenger" hlp:Clip.ToBounds="True">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="BoardingPassScanStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.1">
                                        <VisualTransition.GeneratedEasingFunction>
                                            <BackEase EasingMode="EaseOut" Amplitude="0.1"/>
                                        </VisualTransition.GeneratedEasingFunction>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="AwaitingBoardingPass" />
                                <VisualState x:Name="ProcessingBoardingPass">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="grdAwaitingScan" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdUpdatingDCS" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdScanKO" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdScanOK" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdScanError" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="BoardingPassOK">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="grdAwaitingScan" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdUpdatingDCS" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdScanKO" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdScanOK" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:.5" />
                                        <DoubleAnimation Storyboard.TargetName="grdScanError" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:.5" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <i:Interaction.Behaviors>
                            <ic:DataTriggerBehavior Binding="{Binding Path=DataContext.ScanStatus, ElementName=rootPage, Converter={StaticResource ScanStatusToStringConverter}}" Value="AwaitingScan" ComparisonCondition="Equal">
                                <ic:GoToStateAction StateName="AwaitingBoardingPass" />
                            </ic:DataTriggerBehavior>
                            <ic:DataTriggerBehavior Binding="{Binding Path=DataContext.ScanStatus, ElementName=rootPage, Converter={StaticResource ScanStatusToStringConverter}}" Value="UpdatingDCS" ComparisonCondition="Equal">
                                <ic:GoToStateAction StateName="ProcessingBoardingPass" />
                            </ic:DataTriggerBehavior>
                            <ic:DataTriggerBehavior Binding="{Binding Path=DataContext.ScanStatus, ElementName=rootPage, Converter={StaticResource ScanStatusToStringConverter}}" Value="ScanOK" ComparisonCondition="Equal">
                                <ic:GoToStateAction StateName="BoardingPassOK" />
                            </ic:DataTriggerBehavior>
                        </i:Interaction.Behaviors>

                        <Grid Name="grdAwaitingScan" Grid.Row="1" Margin="5,5,5,15" Opacity="1">

                        </Grid>

                        <Grid Name="grdUpdatingDCS" Grid.Row="1" Margin="5,5,5,15" Opacity="0">

                        </Grid>

                       <Grid Name="grdScanOK" Grid.Row="1" Margin="5,5,5,15" Opacity="0">


                        </Grid>
                    </Grid>
                </DataTemplate>
            </HubSection>

我遇到的问题,当我的状态发生变化并调用Visual状态时,我收到错误目标grdBoardPassenger没有定义任何VisualStateGroups

有人能指出我正确的方向吗?我一直在调查这个问题,我找到的最接近答案的是与Windows Phone 8相关的内容。

1 个答案:

答案 0 :(得分:1)

解决方案是简单地将数据模板的内容包装在UserControl中。显然,这是由于VisualStateManager需要如何绑定到控件而不是框架元素。