0

我目前正在创建一个 Metro 风格应用程序,并希望使用FlipView控件来像 WPF 和 winforms 中的选项卡控件一样工作,请任何人帮助我吗?

4

3 回答 3

1

你会像FlipViewItems放入. 要添加选项卡 - 您可以使用with使其检查状态与选择状态同步。或者,您可以为标题栏设置一个重度样式。FlipViewTabItemsTabControlStackPanelTextRadioButtonStyled RadioButtonsFlipViewListView

于 2014-09-24T18:19:07.197 回答
1

我通过编辑flipviewitem模板并使其视图像想要的标签页视图来解决它。然后我在每个项目的顶部添加了一个按钮来激活它。

于 2014-09-25T13:12:23.807 回答
0

我们在 WP8.1 中没有 Tab Control,但我们可以使用 FlipView 进行自定义。翻转视图有一个属性选择索引,因此我们可以设置我们想要的视图。

创建一个 xaml 页面,例如 MainPage.xaml

对于标签页眉

<Border BorderThickness="0,0,0,1" BorderBrush="White" >
        <Grid Grid.Row="0" Background="Black" x:Name="navigateHead"   >

        <TextBlock x:Name="appbarSports" Text="Sports"  Tapped="appbarSports_Tapped"  TextAlignment="Center" Width="80" Margin="0,34,320,7"  />
        <TextBlock x:Name="appbarCars" Text="Cars"  Tapped="appbarCars_Tapped" Margin="160,34,160,7" TextAlignment="Center" />
        <TextBlock x:Name="appbarHomes" Text="Homes"  Tapped="appbarHomes_Tapped" Margin="80,34,240,7" TextAlignment="Center"  />

            <Image x:Name="imgLine0" Source="ms-appx:///Images/white.png" Width="80" Height="3" Stretch="Fill"  Margin="0,55,320,1"  ></Image>
            <Image x:Name="imgLine1" Source="ms-appx:///Images/white.png" Width="80" Height="3" Stretch="Fill"  Margin="81,55,239,1" Visibility="Collapsed" />
            <Image x:Name="imgLine2" Source="ms-appx:///Images/white.png" Width="80" Height="3" Stretch="Fill"  Margin="162,55,158,1" Visibility="Collapsed"  />


        </Grid>
    </Border>

对于翻转视图 XAML 代码是

<Grid  Grid.Row="1"   >
        <FlipView x:Name="flipControl" SelectionChanged="flipControl_SelectionChanged" >
            <FlipViewItem >
                <ListView x:Name="listViewForSports" >
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Image  Stretch="Fill" Source="{Binding SportsImage}"></Image>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </FlipViewItem>
            <FlipViewItem >
                <ListView x:Name="listViewForHomes">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Image Source="{Binding HomesImage}" Stretch="Fill"></Image>
      </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </FlipViewItem>
            <FlipViewItem >
                <ListView x:Name="listViewForCars">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Image Source="{Binding CarsImage}" Stretch="Fill"></Image>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </FlipViewItem>
        </FlipView>
    </Grid>`

并在文件 MainPage.xaml.cs 后面编写代码

只需全局初始化这些:

public sealed partial class MainPage : Page
{
    List<Sports> listOfSports;
    List<Cars> listOfCars;
    List<Homes> listOfHomes;
    public MainPage()
    {
        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;
    }

页面初始化时将数据绑定到 FlipView 控件

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        flipControl.SelectedIndex = 0;
        // TODO: Prepare page for display here.

        // TODO: If your application contains multiple pages, ensure that you are
        // handling the hardware Back button by registering for the
        // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
        // If you are using the NavigationHelper provided by some templates,
        // this event is handled for you.
        GetData();
    }

此方法将绑定

public void GetData()
    {
     listOfSports = new List<Sports>();
        for (int i = 1; i < 9; i++)
        {
            listOfSports.Add(new Sports() { SportsImage = @"ms-appx:///Images/Sports/image" + i.ToString() + ".jpg" });
        }

        listViewForSports.ItemsSource = listOfSports;

       listOfCars = new List<Cars>();
        for (int i = 1; i < 14; i++)
        {
            listOfCars.Add(new Cars() { CarsImage = @"ms-appx:///Images/Cars/image" + i.ToString() + ".jpg" });
        }

        listViewForCars.ItemsSource = listOfCars;

      listOfHomes = new List<Homes>();
        for (int i = 1; i < 9; i++)
        {
            listOfHomes.Add(new Homes() { HomesImage = @"ms-appx:///Images/Homes/image" + i.ToString() + ".jpg" });
        }

        listViewForHomes.ItemsSource = listOfHomes;

    }
    public class Cars
    {
      public  string CarsImage { get; set; }
    }
    public class Sports
    {
        public string SportsImage { get; set; }
    }
    public class Homes
    {
        public string HomesImage { get; set; }
    }`

 I did with tap event to navigation withing flip view` private void appbarSports_Tapped(object sender, TappedRoutedEventArgs e)
    {
       // TextBlock a = sender as TextBlock;
       // imgLine0.Margin = new Thickness(a.Margin.Left, 55, a.Margin.Right, 1);
        flipControl.SelectedIndex = 0;
        method(0);
    }

    private void appbarCars_Tapped(object sender, TappedRoutedEventArgs e)
    {

      //  TextBlock a = sender as TextBlock;
        //imgLine0.Margin = new Thickness(a.Margin.Left, 55, a.Margin.Right, 1);
        flipControl.SelectedIndex = 2;
        method(2);

    }

    private void appbarHomes_Tapped(object sender, TappedRoutedEventArgs e)
    {
       // TextBlock a = sender as TextBlock;
      // imgLine0.Margin = new Thickness(a.Margin.Left, 55, a.Margin.Right, 1);

        flipControl.SelectedIndex = 1;
        method(1);


    }

我也用于当用户翻转所以我使用 FlipView.SelectionChanged 事件

private void flipControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

        FlipView viewControl = sender as FlipView;

        int a = viewControl.SelectedIndex;
       method(a);

    }

此方法()有助于更改 imageLine 位置

 public void method(int a)
    {
        if (imgLine0 != null)
        {
            switch (a)
            {
                case 0:

                    imgLine0.Visibility = Visibility.Visible;

                    imgLine1.Visibility = Visibility.Collapsed;
                    imgLine2.Visibility = Visibility.Collapsed;
                    break;
                case 1:

                    imgLine0.Visibility = Visibility.Collapsed;

                    imgLine1.Visibility = Visibility.Visible;
                    imgLine2.Visibility = Visibility.Collapsed;
                    break;
                case 2:
                    imgLine0.Visibility = Visibility.Collapsed;

                    imgLine1.Visibility = Visibility.Collapsed;
                    imgLine2.Visibility = Visibility.Visible;
                    break;
            }
        }
    }   
于 2015-10-13T14:34:41.433 回答