Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Big thanks to Xamarin

$
0
0

I normally come on the forums to moan about something not working, but I have spent the last couple of days really trying to understand Xamarin forms, I needed to wait for the unified version so I could kill two birds with one stone. I have several projects to re-write in forms that are just IOS projects but every project needs to be cross platform now so this is the right time to move across. My experience of Xamarin forms so far as been great, well done I can see a lot of hard work has gone into forms, keep up the good work.

Below is one of the ViewCells which is at the core of my project (works well I have posted it as an example for others working on ViewCells), I have about 30 different ones to create, but once done the rest of the app should be pretty straight forward, to move over to forms.

using System;
using Xamarin.Forms;

namespace Doser
{
    class SupplementCell : ViewCell
    {
        public SupplementCell ()
        {
            // Top row
            var lblSupplementName = new Label {
                FontAttributes = FontAttributes.Bold,
                FontSize = 13,
                FontFamily = "Verdana",
                TextColor = Color.Green,
                XAlign = TextAlignment.Start,
                BackgroundColor = Color.Transparent
            };
            lblSupplementName.SetBinding (Label.TextProperty, "SupplementName");
            AbsoluteLayout.SetLayoutBounds (lblSupplementName, new Rectangle (0f, 0f, 150f, 20f));
            AbsoluteLayout.SetLayoutFlags (lblSupplementName, AbsoluteLayoutFlags.PositionProportional);

            // Second row left side
            var lblManufacturer = new Label {
                FontSize = 10,
                FontFamily = "Verdana",
                TextColor = Color.Gray,
                XAlign = TextAlignment.Start,
                BackgroundColor = Color.Transparent,
            };
            lblManufacturer.SetBinding (Label.TextProperty, "Manufacturer");
            lblManufacturer.BindingContextChanged += (object sender, EventArgs e) => {
                Label lbl = (Label)sender;
                lblManufacturer.Text = "Man: " + lbl.Text; 
            };
            AbsoluteLayout.SetLayoutBounds (lblManufacturer, new Rectangle (0f, 15f, 150f, 20f));
            AbsoluteLayout.SetLayoutFlags (lblManufacturer, AbsoluteLayoutFlags.None);

            // Second row right side
            var lblSupplier = new Label {
                FontSize = 10,
                FontFamily = "Verdana",
                TextColor = Color.Gray,
                XAlign = TextAlignment.End,
                BackgroundColor = Color.Transparent
            };
            lblSupplier.SetBinding (Label.TextProperty, "Supplier");
            lblSupplier.BindingContextChanged += (object sender, EventArgs e) => {
                Label lbl = (Label)sender;
                lblSupplier.Text = "Sup: " + lbl.Text; 
            };
            AbsoluteLayout.SetLayoutBounds (lblSupplier, new Rectangle (1f, 15f, 120f, 20f));
            AbsoluteLayout.SetLayoutFlags (lblSupplier, AbsoluteLayoutFlags.XProportional);

            // Third row left side
            var lblFirstTaken = new Label {
                FontSize = 10,
                FontFamily = "Verdana",
                TextColor = Color.Gray,
                XAlign = TextAlignment.Start,
                BackgroundColor = Color.Transparent
            };
            lblFirstTaken.SetBinding (Label.TextProperty, "FirstTaken");
            lblFirstTaken.BindingContextChanged += (object sender, EventArgs e) => {
                Label lbl = (Label)sender;
                lblFirstTaken.Text = "First: " + lbl.Text; 
            };
            AbsoluteLayout.SetLayoutBounds (lblFirstTaken, new Rectangle (0f, 25f, 150f, 20f));
            AbsoluteLayout.SetLayoutFlags (lblFirstTaken, AbsoluteLayoutFlags.None);

            // Third row right side
            var lblLastTaken = new Label {
                FontSize = 10,
                FontFamily = "Verdana",
                TextColor = Color.Gray,
                XAlign = TextAlignment.End,
                BackgroundColor = Color.Transparent
            };
            lblLastTaken.SetBinding (Label.TextProperty, "LastTaken");
            lblLastTaken.BindingContextChanged += (object sender, EventArgs e) => {
                Label lbl = (Label)sender;
                lblLastTaken.Text = "Last: " + lbl.Text; 
            };
            AbsoluteLayout.SetLayoutBounds (lblLastTaken, new Rectangle (1f, 25f, 160f, 20f));
            AbsoluteLayout.SetLayoutFlags (lblLastTaken, AbsoluteLayoutFlags.XProportional);

            var absLayout = new AbsoluteLayout () {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            absLayout.Children.Add (lblSupplementName);
            absLayout.Children.Add (lblManufacturer);
            absLayout.Children.Add (lblSupplier);
            absLayout.Children.Add (lblFirstTaken);
            absLayout.Children.Add (lblLastTaken);
            this.View = absLayout;
        }
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles