如何使用c#

时间:2015-05-25 12:36:59

标签: windows-phone-8.1 win-universal-app

我正在为Windows手机开发应用程序。我正在使用flipview来显示细节。此flipview包含三个控件并使用滑动更改视图。我想在点击按钮时更改视图。

参见我的代码:

<FlipView x:Name="flip" Grid.Row="1" Grid.ColumnSpan="4" Grid.Column="0" Margin="0,0,0,0.333" Grid.RowSpan="2">
            <FlipViewItem>
                    <Button Foreground="White" Background="Black" x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Tapped="btnAdd_Tapped" ></Button>
            </FlipViewItem>
            <FlipViewItem>
                <Button x:Name="btny2" Content="mov" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Tapped="btny2_Tapped" ></Button>
            </FlipViewItem>
            <FlipViewItem>
                <Button x:Name="btnUpdate" Content="Upd" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" Tapped="btnupdate_Tapped" ></Button>
            </FlipViewItem>
            <FlipViewItem>
                <Button x:Name="btnRemove" Content="Rem" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Tapped="btnRemove_Tapped" ></Button>
            </FlipViewItem>
        </FlipView>




private void btnAdd_Tapped(object sender, TappedRoutedEventArgs e)
        {
            flip.SelectedIndex++;

        }

        private void btnupdate_Tapped(object sender, TappedRoutedEventArgs e)
        {
            flip.SelectedIndex++;
        }

        private void btny2_Tapped(object sender, TappedRoutedEventArgs e)
        {
            flip.SelectedIndex++;
        }

        private void btnRemove_Tapped(object sender, TappedRoutedEventArgs e)
        {
            flip.SelectedIndex++;
        }
but it is not working at all.

3 个答案:

答案 0 :(得分:0)

按钮点击事件只需增加/减少所选索引..

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    SelectedIndex++;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    SelectedIndex--;
}

答案 1 :(得分:0)

尝试这样的事情

in .xaml

<FlipView x:Name="flip" Grid.Row="1" Grid.ColumnSpan="4" Grid.Column="0" Margin="0,0,0,0.333" Grid.RowSpan="2">

    <Button Foreground="White" Background="Black" x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Tapped="btnAdd_Tapped" ></Button>

    <Button x:Name="btny2" Content="mov" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Tapped="btny2_Tapped" ></Button>

    <Button x:Name="btnUpdate" Content="Upd" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" Tapped="btnupdate_Tapped" ></Button>

    <Button x:Name="btnRemove" Content="Rem" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Tapped="btnRemove_Tapped" ></Button>

</FlipView>

in .cs

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    var newItemIndex = (flip.SelectedIndex + 1)
    flip.SelectedIndex = newItemIndex;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    var newItemIndex = (flip.SelectedIndex - 1)
    flip.SelectedIndex = newItemIndex;
}

答案 2 :(得分:0)

如果你把按钮放在flipview之外然后尝试改变它的索引,那么我找到了一些解决方法 请查看以下代码,使用网格或画布,我们可以轻松地将按钮放在Flipview上

XAML

 <Grid x:Name="LayoutRoot">



    <FlipView x:Name="SlideHub"  ManipulationMode="Rotate" FlowDirection="LeftToRight"     UseTouchAnimationsForAllNavigation="True" Grid.Row="1"  >

        <FlipViewItem  >

        </FlipViewItem>

        <FlipViewItem  >

        </FlipViewItem>

        <FlipViewItem  >

        </FlipViewItem>

        <FlipViewItem >
        </FlipViewItem>

    </FlipView>


    <Image Tapped="slideBankingNext_tapped" Grid.Row="0" Width="40" Margin="0 10 10 20" HorizontalAlignment="Right" VerticalAlignment="Bottom" Source="/Images/welcome_next.png"  />

</Grid>

C#代码

 private void slideBankingNext_tapped(object sender, TappedRoutedEventArgs e)
    {
        var newItemIndex = (SlideHub.SelectedIndex + 1);
            SlideHub.SelectedIndex = newItemIndex;
    }