Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms - Counterpart to <div> in XAML?

I am new to XAML / Xamarin.forms and come from a web-development background.

I am looking to make a box containing with text and images (like that can be done using a <div> in HTML). Please explain how to approach this with XAML & Xamarin.forms.

Also, if anybody knows a resource that lists the available tags in XAML (like w3schools for HTML), please pass that on to me.

Thanks in advance :)

like image 917
Dhruv Avatar asked Jun 14 '16 13:06

Dhruv


People also ask

What is XAML in Xamarin forms?

Xamarin.Forms XAML Basics. XAML—the eXtensible Application Markup Language—allows developers to define user interfaces in Xamarin.Forms applications using markup rather than code. XAML is never required in a Xamarin.Forms program, but it is often more succinct and more visually coherent than equivalent code, and potentially toolable.

What is the translateextension in Xamarin forms?

The article explains how to use Xamarin.Forms XAML markup extensions to extend the power and flexibility of XAML by allowing element attributes to be set from sources other than literal text strings. The TranslateExtension allows users to handle multi-language support in XAML at runtime.

What is compiled bindings in Xamarin?

In simple words, Compiled Bindings just tells your app to compile the XAML stuff before you run the app. Catches spelling errors and other issues with data binding at compile-time and build time itself. Let's take the XAML code from my article BindableLayout as an example for understanding what is Compiled Bindings in Xamarin.Forms.

What are behaviors in Xamarin forms?

Behaviors are written in code and added to controls in XAML or code. Behaviors are the best way to validate the user inputs such as email, phone number, etc. Start by creating a new Xamarin.Forms project.


2 Answers

Why not check out the Xamarin documentation on this? It is quite extensive and should help you with the basics!

There isn't a exact equivalent of a div. It depends on what you want to do. It all starts with a Page. You see the types of pages below.

Xamarin.Forms pages

That will be the base of your app. Within this Page you can have one VisualElement, which kind of forces you to use a Layout.

Here you see all the layouts that are available to you;

Xamarin.Forms layouts

The good news is you can nest Layouts!

In a Layout you can specify your controls (of type View).

To get back to your question; the behaviour is different than a div. If you take a StackLayout for example your nested controls will be stacked on top of each other and you don't have to worry about spacing, margin, etc. Another option is to go for a Grid which gives you a bit of flexibility. So it's not just a container it also means something in terms of how it is placed on the screen.

I also explain some basics on my blog here and here but there are a lot of resources out there which can help you get started.

like image 72
Gerald Versluis Avatar answered Sep 25 '22 07:09

Gerald Versluis


Just use a Frame:

<StackLayout>
    <Frame x:Name="MyPanelABC">
        <Label Text="My Stuff" />
    </Frame>
</StackLayout>

private void setupPanelABC(bool isVisiblePanelABC){
    MyPanelABC.IsVisible = isVisiblePanelABC;
}
like image 26
Joe Avatar answered Sep 21 '22 07:09

Joe