windows phone 8的枢轴页面加载枢轴事件未触发

本文关键字:事件 加载 phone windows | 更新日期: 2023-09-27 18:17:16

我刚开始为Windows phone 8开发通用表单。不,我想测试一个特定的透视项是否被选中,那么它应该触发一个函数来加载一个网格到那个透视项。

这里是我的xaml和我的代码到目前为止XAML:
 <phone:Pivot Name="mainpivot" Title="MY APPLICATION" LoadingPivotItem="mainpivot_LoadingPivotItem" LoadedPivotItem="mainpivot_LoadedPivotItem_1">
        <!--Pivot item one-->
        <phone:PivotItem Name="staticpivot" Header="static">
            <!--Double line list with text wrapping-->
            <Grid Name="staticGrid" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>

                </Grid.RowDefinitions>
                <TextBox Name="txtUsername" Grid.Column="1" Height="70"></TextBox>
                <TextBox Name="txtPassword" Grid.Row="1" Height="70" Grid.Column="1"></TextBox>
                <TextBox Name="txtdescription" Grid.Row="2" Height="150"  Grid.Column="1" TextWrapping="Wrap"></TextBox>

                <TextBlock Height="40" Text="USERNAME" HorizontalAlignment="Center"></TextBlock>
                <TextBlock Height="40" Text="PASSWORD" HorizontalAlignment="Center" Grid.Row="1"></TextBlock>
                <TextBlock Height="40" Text="DESCRIPTION" HorizontalAlignment="Center" Grid.Row="2"></TextBlock>
                <Button Grid.Row="4" Grid.ColumnSpan="2" Tap="Button_Tap">SAVE DATA</Button>
            </Grid>
        </phone:PivotItem>
        <!--Pivot item two-->
        <phone:PivotItem x:Name="genericpivot" Header="generic">
            <!--Double line list no text wrapping-->
        </phone:PivotItem>
    </phone:Pivot>

你可以看到第二个枢轴里面什么都没有,我要用控件动态填充它。

问题在代码中:

        private void mainpivot_LoadedPivotItem_1(object sender, PivotItemEventArgs e)
    {
        if (e.Item.Name == "genericpivot")
        {
            loadDetailForPivot();
        }
    }
当我调试并在那里设置断点时,

这个函数不会触发。有人能告诉我为什么吗?或者给出一个解释它的链接。

windows phone 8的枢轴页面加载枢轴事件未触发

澄清一下,您是在尝试填充选中的数据透视项吗?

我相信你之后是拿起一个变化的枢轴控件选定索引,如(VB.net,对不起):

  Private Sub PivotItem_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles PivotItem.SelectionChanged
       If PivotItem.SelectedIndex = 1 Then LoadDetailForPivot
End Sub
然而

…你为什么不事先加载控件?这不是更快吗(即,当用户转向时加载内容时没有延迟)。

我在之前的一个应用程序中这样做过,结果旋转很不稳定。