Xamarin.Forms中的动态UI [英] Dynamic UI in Xamarin.Forms

查看:299
本文介绍了Xamarin.Forms中的动态UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向移动应用程序页面添加一个可滚动菜单.
此处转帐,帐户,付款和交易都是通过XML文件生成的.
其余是静态布局.

我正在使用Xamarin.Forms.
我想知道如何动态生成UI组件,并使用Xamarin.Forms将它们附加到占位符.

I would like to add a scrollable menu to a mobile app page.
Here Transfer, Accounts, Payment and Transaction are generated from an XML file.
The rest is static layout.

I am using Xamarin.Forms.
I would like to know how to generate UI components dynamically and attach them to a placeholder using Xamarin.Forms.

推荐答案

动态UI的创建很简单,就像人们所说的那样,并且有很多示例.但是我认为问题在于根据您的需求创建自己的控件.例如,我最终编写了自己的带有图像的按钮,如下所示:

Dynamic UI creation is simple like the people said and there are many examples. But i think the problem is creating your own control according to your needs. For example i ended up with writing my own button with image in it like this:

因此,您必须编写一种方法来创建垂直的堆栈布局(例如说外部容器),然后将一个水平容器添加到该外部容器"(可以说内部容器),而不是在此内部容器",并制作"innerContainer.Horizo​​ntalOptions = LayoutOptions.Center"等.如果要边框,它会变得很复杂:)

So you have to write a method that creates a vertical stack layout (lets say outer container),and add a horizontal container to that "outer container" (lets say inner container) than add an image and a label to this "inner container" and make "innerContainer.HorizontalOptions = LayoutOptions.Center" etc. If you want border it goes complicated :)

Vertical Stack (whole container)
->Vertical Stack (height 2px) upper border
->Horizontal Stack (to hold middle controls,left border,inner image and text holder, right border etc.)
    ->Horizontal Stack (width 2 px) left border
    ->Vertical Stack (layoutOptions=Fillandexpand)
        ->Image (layoutOptions=Center)
        ->Label (layoutOptions=Center)
    ->Horizontal Stack (width 2 px) right border
->Vertical Stack (height 2px) lower border

因此,您必须像这样的层次结构一样加入控件.首先想想如何用现有控件绘制控件而不是编码:)希望我能说清楚.

So you have to join the controls like this hierarcy. First think how can you draw your control with existing controls than code it :) Hope i made my self clear.

这篇关于Xamarin.Forms中的动态UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆