亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Xamarin.forms 輪播視圖列表列表

Xamarin.forms 輪播視圖列表列表

C#
慕姐4208626 2023-09-24 10:46:09
我有一個使用輪播視圖的 xamarin.forms 應用程序。我的輪播視圖每個視圖有 6 個項目。但現在它每次視圖顯示一個項目。我知道問題是我需要創建一個List 的 List。但我被困在這個問題上。我預期的輪播視圖輸出是這樣的。但我現在得到的是這樣的我原來的包含數據的列表是這樣的。 ObservableCollection<SECHomescreenData> resultObjForSEC = callForSECtilesScreen.APICallResult<ObservableCollection<SECHomescreenData>>();我的 SECHomescreenData。  public partial class SECHomescreenData   {               public string Status { get; set; }           public string Countered { get; set; }   }當我將此列表綁定到我的輪播視圖時,它只會在每個視圖中顯示一個項目。我想要實現的是將數據填充到輪播的 6 項中,如果有第 7 項,則轉到輪播視圖的下一頁。那么我怎樣才能實現這一目標呢?如果需要列表列表,我該怎么做?任何幫助表示贊賞。
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

實際上,您不需要使用List of List。設置每個Frame的大?。▽挾鹊扔谄聊粚挾鹊?/2,高度等于屏幕高度的1/3)。并設置屬性 Span="3"


CarouselView在 Xamarin.Forms 4.0 之后發布。


<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             xmlns:d="http://xamarin.com/schemas/2014/forms/design"

             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

             mc:Ignorable="d"

             x:Name="contentPage"   // set the name of the contentpage

             x:Class="xxx.MainPage">

<CarouselView  ItemsSource="{Binding MyItems}"  BackgroundColor="Transparent" HorizontalOptions="Center" VerticalOptions="Center">

        <CarouselView.ItemsLayout>

            <GridItemsLayout SnapPointsAlignment="Center"  SnapPointsType="Mandatory" Span="3" Orientation="Horizontal"/>

        </CarouselView.ItemsLayout>

        <CarouselView.ItemTemplate>

            <DataTemplate>

                <Frame WidthRequest="{Binding Source={x:Reference contentPage}, Path=BindingContext.FrameWidth}" HeightRequest="{Binding Source={x:Reference contentPage}, Path=BindingContext.FrameHeight}" HasShadow="False" HorizontalOptions="FillAndExpand" IsClippedToBounds="True"  BackgroundColor="#4D2F4F4F" BorderColor="#294145">


                    <StackLayout HorizontalOptions="FillAndExpand">

                        <Grid >

                            <Grid.RowDefinitions>

                                <RowDefinition Height="Auto"/>

                                <RowDefinition Height="Auto"/>

                                <RowDefinition Height="Auto"/>

                                <RowDefinition Height="Auto"/>

                            </Grid.RowDefinitions>

                            <BoxView Grid.Row="0" Margin="2,2,10,2" HeightRequest="1" Color="LightGreen"></BoxView>

                            <Label Text="111111" Grid.Row="1" HorizontalOptions="StartAndExpand" FontSize="Small" TextColor="LightGray" Margin="2,0,0,0" >

                            </Label>

                            <Label Text="153" TextColor="White" HorizontalOptions="StartAndExpand" FontSize="Medium" Grid.Row="2" Margin="2,0,0,0" >

                            </Label>

                            <Image Source="alllead.png" HorizontalOptions="EndAndExpand" HeightRequest="30" Grid.Row="3" Margin="0,0,5,0"></Image>

                        </Grid>

                    </StackLayout>

                </Frame>

            </DataTemplate>

        </CarouselView.ItemTemplate>

</CarouselView>

在共享項目 App.xaml.cs 中

public static double ScreenWidth;

public static double ScreenHeight;

在 Android MainActivity.cs 中

protected override void OnCreate(Bundle savedInstanceState)

{

   TabLayoutResource = Resource.Layout.Tabbar;

   ToolbarResource = Resource.Layout.Toolbar;


   base.OnCreate(savedInstanceState);


   Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            

   Forms.SetFlags("CollectionView_Experimental");

   global::Xamarin.Forms.Forms.Init(this, savedInstanceState);


   App.ScreenWidth = Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density; 

   App.ScreenHeight =Resources.DisplayMetrics.HeightPixels/Resources.DisplayMetrics.Density; 


   LoadApplication(new App());

}

在 iOS 中

public override bool FinishedLaunching(UIApplication app, NSDictionary options)

{

    //...

    App.ScreenWidth = UIScreen.MainScreen.Bounds.Width;

    App.ScreenHeight = UIScreen.MainScreen.Bounds.Height;

    //...

}


在代碼隱藏或 ViewModel 中

public double FrameHeight { get; private set; }

public double FrameWidth { get; private set; }


//...


FrameHeight = App.ScreenHeight/3.0;

FrameWidth = App.ScreenWidth/2.0;


查看完整回答
反對 回復 2023-09-24
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號