c# – 如何在Xamarin Forms的表中显示不同类型的项目

c# – 如何在Xamarin Forms的表中显示不同类型的项目,第1张

概述期望的结果: 我有一个对象列表,其中包含菜单中每个部分的标题,在此列表中我有图像列表和其他信息 我一直在努力正确地展示它们 我的xaml: <ContentPage.Content> <TableView Intent="Form"> <TableRoot> <TableSection Title="Getting Started"> 期望的结果:

我有一个对象列表,其中包含菜单中每个部分的标题,在此列表中我有图像列表和其他信息

我一直在努力正确地展示它们

我的xaml:

<ContentPage.Content>    <tableVIEw Intent="Form">        <tableRoot>            <tableSection title="Getting Started">                <VIEwCell>                    <GrID VerticalOptions="FillAndExpand" padding = "20,0" >                        <GrID.ColumnDeFinitions>                            <ColumnDeFinition WIDth="auto" />                        </GrID.ColumnDeFinitions>                        <GrID.RowDeFinitions>                            <RowDeFinition Height="auto" ></RowDeFinition>                            <RowDeFinition Height="auto" ></RowDeFinition>                        </GrID.RowDeFinitions>                        <StackLayout GrID.Row="0" x:name="Titre" OrIEntation="Horizontal">                        </StackLayout>                        <ScrollVIEw GrID.Row="1">                            <StackLayout                                padding="0"                                x:name="Image">                            </StackLayout>                        </ScrollVIEw>                    </GrID>                </VIEwCell>            </tableSection>        </tableRoot>    </tableVIEw></ContentPage.Content>

C#方法:

private voID PopulateProductsLists(List<PlanDeFinition> ListArticles)        {            for (var i = 0; i < ListArticles.Count; i++)                {                    //display Title                  Titre.Children.Add((new Label { Text = ListArticles[i].name,Style = Device.Styles.TitleStyle,FontAttributes = FontAttributes.Bold,Textcolor = color.White }));                //display Images from  ListArticles[i].ArticlesAvailable                for (int j= 0; j < ListArticles[i].ArticlesAvailable.Count; j++)                    {                        ListArticles[i].ArticlesAvailable[j].ImageProduit = "https://fit-plans.com/" + ListArticles[i].ArticlesAvailable[j].UrlSmallimage;                        Image image = new Image();                        image.source = ImageSource.FromUri(new Uri(ListArticles[i].ArticlesAvailable[j].ImageProduit));                        Image.Children.Add(image);                }

我错的是什么?

解决方法 首先,这是我的错误:

1-不使用可滚动视图

2-使用不同的堆栈布局

我的问题的补救措施:

<!----Scrollable vIEw MUST be used otherwIDe data simply won't appear  --->    <ScrollVIEw                GrID.Column="0"                GrID.Row="1">                <GrID                     RowSpacing="3"                       x:name="MyGrID"                    ClassID="myGrID">                    <GrID.ColumnDeFinitions>                        <ColumnDeFinition WIDth="*" />                           </GrID.ColumnDeFinitions>                    <GrID.RowDeFinitions>                        <RowDeFinition Height="*"></RowDeFinition>                    </GrID.RowDeFinitions>                    <StackLayout VerticalOptions="FillAndExpand"                                 HorizontalOptions="FillAndExpand"                        x:name="ProduitsLayout">                       <!----Products will be displayed here --->                    </StackLayout>                </GrID>            </ScrollVIEw>

并在代码背后:

private voID PopulateProductsLists(List<PlanDeFinition> ListArticles)            {                int labelindex = 0;                int count = 0;                for (var i = 0; i < ListArticles.Count; i++)                {                   //Calling a vIEw to display data                    item = new PlanorderTemplate();                                 var lastHeight = "100";                    var y = 0;                    int column = 1;                    var productTapGestureRecognizer = new TapGestureRecognizer();                //Add label in the stack layout                    ProduitsLayout.Children.Add((new Label                    {                        Text = ListArticles[i].name,Textcolor = color.Black                    }));                    for (int j = 0; j < ListArticles[i].ArticlesAvailable.Count; j++)                    {                        productTapGestureRecognizer.Tapped += OnProductTapped;                        item = new PlanorderTemplate();                        ListArticles[i].ArticlesAvailable[j].thumbnailHeight = lastHeight;                       //Applying binding to the vIEw in order to display data                            item.BindingContext = ListArticles[i].ArticlesAvailable[j];                            item.GestureRecognizers.Add(productTapGestureRecognizer);        //This is mandatory you need to call the add the vIEw page to the stack layout                            ProduitsLayout.Children.Add(item);    }    }}

现在我正在讨论的视图页面:ProduitsLayout.xaml

配置我想用步进器加载的图像

<StackLayout OrIEntation="Vertical"        Spacing="1">        <ffimageloading:CachedImage             FadeAnimationEnabled="true"             Source="{Binding ImageProduit}"             HeightRequest="{Binding thumbnailHeight}"             Aspect="AspectFill"/>        <Label x:name="lbldisp"  Text="1" VerticalOptions="Center" HorizontalOptions="Center"></Label>        <Stepper Minimum="0" Maximum="10" Increment="1" HorizontalOptions="FillAndExpand" VerticalOptions="CenterandExpand" ValueChanged="OnValueChanged" /></StackLayout>
总结

以上是内存溢出为你收集整理的c# – 如何在Xamarin Forms的表中显示不同类型的项目全部内容,希望文章能够帮你解决c# – 如何在Xamarin Forms的表中显示不同类型的项目所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1233161.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存